2 回答
已采纳
紫帆梓
TA贡献3条经验 获得超3个赞
使用promise模式:
service代码
app.service('IndexServ',function($http,$q){
this.getData = function(){ //暴露一个接口
//获取数据,并缓存数据
return $http.get('data/data.json',{cache:true}).then(function (d) {
this.data = d;
return $q.when(d);
}, function (d) {
return $q.reject(d);
});
};
});controller代码
app.controller('IndexCtrl',function($scope,IndexServ){
IndexServ.getData().then(function(res){ //调用获取数据的接口
$scope.data = res.data;
});
}- 2 回答
- 0 关注
- 3659 浏览
添加回答
举报
0/150
提交
取消
