angular js 多处获取ajax数据的方法

angular js 多处获取ajax数据的方法

var app=angular.module("cart",[]);
app.service("getData",function ($http) {
return{
ajax:function () {
return $http.get("product.json");
}
}
});

app.controller("listCtrl",function ($scope,getData) {
getData.ajax().then(function (res) {
$scope.data=res.data;
})
});
app.controller("detailCtrl",function ($scope,getData) {
getData.ajax().then(function (res) {
$scope.data=res.data;
})
});
原文地址:https://www.cnblogs.com/yaomengli/p/6814119.html