angularjs - Parsing JSON file with angular.js -


i want parse bitcoin price json file angular.js.

the json source this blockchain api.

the code use angular.js:

<div ng-app="myapp" ng-controller="customersctrl">    <ul>     <li ng-repeat="x in price">       {{ x.15m + ', ' + x.last }}     </li>   </ul> </div>  <script>   var app = angular.module('myapp', []);   app.controller('customersctrl', function($scope, $http) {     $http.get("https://blockchain.info/de/ticker")          .success(function (response) {$scope.price = response.usd;});   }); </script> 

the result should 15m price , comma separated latest price.

my guess messed near response.usd, after 1 hour, still didn't find how properly.

please help!

it appears getting error blockchain site. have single-origin policy set on server protects them click-jacking attacks. here error getting:

xmlhttprequest cannot load https://blockchain.info/de/ticker. no 'access-control-allow-origin' header present on requested resource. origin '<your domain>' therefore not allowed access. 

your options contact site , ask them add server exception, or use sort of curl request server have request hit local copy.

create file called results.php, put in following code:

<?php  try {     $curl = curl_init();     curl_setopt_array($curl, array(         curlopt_returntransfer => 1,         curlopt_url => 'https://blockchain.info/de/ticker'     ));      $result = curl_exec($curl);      echo $result; } catch (exception $e) {     header("http/1.0 500 unable pull ticker results");     echo $e->getmessage(); } ?> 

now in script change to:

<script>   var app = angular.module('myapp', []);   app.controller('customersctrl', function($scope, $http) {     $http.get("results.php")          .success(function (response) {$scope.price = response.usd;});   }); </script> 

also, 1 last thing. ng-repeat going repeat same thing on , on (if can work way) because writing same thing each value in 'x'. maybe consider changing to:

<div ng-app="myapp" ng-controller="customersctrl">     <p>{{price['15m']}}, {{price['last']}}</p> </div> 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -