AngularJS 异步请求数据后,使用 deferred.promise 传值,但很不稳定,刷新10次,只显示2次。
不知道我的代码有什么问题,或者有更好的方法,请赐教!
服务文件:service.js
app.factory('Factory',['$sce','$q','$http',function($sce,$q,$http){var _baseUrl="//api.a.com",deferred = $q.defer(),service={}; service.list=function(_params){ query({item:"/a/index",params:_params}).success(function(data){ if(data.code==0){ deferred.resolve(data.data); }else{ alert("Error"); } }); return deferred.promise; } var query=function(rq){ var item=rq['item'],params=rq['params']; return $http({ method:"POST", url:_baseUrl+item, params:params, headers:{'Content-Type': 'application/x-www-form-urlencoded'} }).error(function(data){ $.notify({message:_ay.system.code.api.error[data.code]},{type:"danger"}); }); }; return service;}
controller.js
app.controller('ctrl.detail',['$scope','$routeParams','Factory',function($scope,$routeParams,Factory){var _param=$routeParams,_id=_param.g,_token=token; $scope.d_detail={}; $scope.detail=function(){ Factory.list({token:_token,device_id:_id}).then(function(data){ $scope.d_detail=data.row; }); }; (init = function(){ $scope.detail(); })();}]);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Factory.device_detail 没看到你定义啊