The getallcountries service method should return the promise generated by $http.get like this:var countryApp = angular.module('countryApp', []);countryApp.service('countryservice', function ($http) {this.getallcountries = function () { return $http.get('js/countries.json');}});countryApp.controller('CountryCtrl', function ($scope, countryservice) { countryservice.getallcountries().success(function(data) { $scope.countries = data; });});另外,请注意您不必向控制器注入 $http 服务.Also, notice that you don't have to inject $http service to the controller. 这篇关于AngularJS 服务不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-12 17:45