标签:灵活 alarm 对象 pre result 操作 list tor for
angularJs 对promise的封装
var deferred = $q.defer();
deferred.promise.then(function(){
var result = {}
cgiSvc.getGameList(result, function () {
$scope.game_list = result.info;
});
},function(result){
})
$timeout(function(){
deferred.resolve()
},100)
then的灵活运用
process_history:function(){
var deferred = $q.defer(); //在方法内声明
var request={};
request.op=‘process_history‘;
gs.post(‘alarm_adapter‘,request,function(ret){
$.each(ret.data,function(k,item){
item.name=item.content;
return item;
})
$scope.process=ret.data;
deferred.resolve(); // ajax成功返回后,执行 resolve操作
if(!$scope.$$phase) {
$scope.$apply();
}
})
return deferred.promise;//类似闭包 返回一个方法内的对象,或方法
},
调用
gs.process_history()
.then(function(){
gs.forbidden();
});
标签:灵活 alarm 对象 pre result 操作 list tor for
原文地址:http://www.cnblogs.com/blog-index/p/6834497.html