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; })});
时间: 2024-11-09 07:07:31