AngularJS Service 异步取回数据
service.js
1 var app = angular.module("Proj.Services", []); 2 app.service("listService", ["$http", function ($http) { 3 return { 4 get: function () { 5 return $http.get("../scripts/json/phones.json").then(function (result) { 6 return result.data; 7 }); 8 } 9 }; 10 }]);
controller.js
app.controller("listCtrl", ["$scope", "listService", function ($scope, listService) { listService.get().then(function (result) { $scope.phones = result; }); }]);