我正在使用AngularJS $resource来获取一些数据。
app.controller('Hello', ['$scope', 'Phone', function($scope, Phone,$http) {
$scope.data=Phone.query();
}]);
mycallback = function(data,$scope){
alert(data.found);
};
app.factory('Phone', ['$resource',function($resource){
return $resource('http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=mycallback', {}, {
query:
{
method:'JSONP',
params:{},
isArray:false,
callback: 'JSON_CALLBACK'
}
});
}]);
错误控制台显示“未捕获SyntaxError:意外令牌:”。请让我知道,怎样才能最好地处理JSONP数据。
发布于 2014-04-23 15:08:28
在访问$scope之前,您必须在工厂中包含它。
app.factory('Phone', ['$resource','$scope',function($resource,$scope){}
]);
发布于 2014-04-24 13:01:43
好的。将回调函数放入控制器中后,我就可以访问$scope了
app.controller('Hello', ['$scope', 'Phone', function($scope, Phone,$http) {
Phone.query();
mycallback = function(data){
$scope.data= data.found;
};
}]);
https://stackoverflow.com/questions/23234871
复制相似问题