延迟对象$q和供应商配置config

时间:2023-03-08 18:23:14
延迟对象$q和供应商配置config

1.angular总的$q和jquery中的延迟对象很类似,用法也差不多

m1.controller('meng',['$scope','$q',function($scope,$q){

    var dfd = $q.defer();
function show(){
setTimeout(function(){
dfd.reject();
},2000);
return dfd.promise;
}
show().then(function(){
alert('成功');
},function(){
alert('失败');
}); }]);

2.服务r的config配置

angular的服务如$interpolate,$anchorScroll都可以惊行一些初始配置:

m1.config(['$anchorScrollProvider',function($anchorScrollProvider){

    $anchorScrollProvider.disableAutoScrolling();

}]);