Receive an array via $resource get method
I can see the received array and params in the console.log, but I can't
echo that array to the view...
That online JSON service returns {"key": "value"}
How to make this {{some_item.key}} to work? Thanks!!
<!DOCTYPE html>
<html ng-app="Simple">
<body>
<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.min.js"></script>
<div ng-controller="SimpleController"></div>
{{some_item.key}}
<script>
angular.module('Simple', ['ngResource']);
function SimpleController($scope, $resource) {
$scope.simple = $resource('http://echo.jsontest.com/key/value',
{callback:'JSON_CALLBACK'},
{get:{method:'JSONP'}}
);
$scope.some_item = $scope.simple.get();
console.log($scope.some_item); // gives a response array
console.log($scope.some_item.key); // undefined
}
</script>
</body>
</html>
No comments:
Post a Comment