0
Edited: Now this example fully works with external json service to see it in live

我可以在 console.log 中看到接收到的数组和参数,但我无法将该数组回显到视图中......

该在线 JSON 服务返回{"key": "value"}

如何使它{{some_item.key}}工作?谢谢!!

<!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">    
    {{some_item.key}}
</div>
<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.key);
}   
</script>
</body>
</html>
4

1 回答 1

2

您需要像这样将插值放在控制器的范围内

<div ng-controller="SimpleController">    
    {{some_item.key}}
</div>
于 2013-08-31T20:42:57.467 回答