我是 AngularJS 的新手,觉得它很有趣,但我对以下情况有点不清楚。
app.factory('deleteFac', function($http){
var factory = {};
factory.edit = function(id){
$http.get('?controller=store&action=getDetail&id=' + id).
success(function(data, status){
/**
got an error on the following
when i use return data; and i get data undefined
in the controller which i get it because its doing a ajax call
you don't get data until the call first.
**/
$scope.detail = data;
})
}
return factory;
})
当我分配给时出现错误$scope
并使用返回数据,无论如何我可以将返回数据分配给$scope
?
你通常不使用$scope
工厂、服务或提供商内部。通常,您会返回promise
(由返回$http
)然后在控制器中处理承诺(你确实有$scope
).
factory.edit = function(id){
return $http.get('?controller=store&action=getDetail&id=' + id);
}
控制器功能:
$scope.edit = function(id) {
deleteFac.edit(id).then(function(response) {
$scope.something = response.model;
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)