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;
})
});