为范围变量赋值GET响应
问题描述:
我开发了我的应用程序,仿真数据如下。为范围变量赋值GET响应
$scope.products=[{serial:1,quantity:30,name:"aaa"},
{serial:2,quantity:10,name:"bbb"}];
还我已经准备牵强从数据库和可用的数据,在http://localhost:8080/myrests/shop/productresource
可以请你帮我我怎样才能分配这个资源将结果返回到上述$scope.products
其余资源。如果你想让它
答
异步使用下面的代码包承诺未来
//功能
var deferred = $q.defer();
$http.get(URL)
.then(function(data, status, headers, config) {
deferred.resolve(data);
console.log("Success " + data);
},
function(data, status, headers, config) {
deferred.reject(data);
console.log("Failure " + status);
});
return deferred.promise;
其他内只需使用$ HTTP
$http.get("http://localhost:8080/myrests/shop/productresource")
.then(function(data, status, headers, config) {
$scope.products = data;
},
function(data, status, headers, config) {
console.log("Failure " + status);
});
非常感谢你,它的工作如预期 – user2582767
请注明答案已解决 –