0
我是AngilarJS的新手。我正在尝试在angularJS中编写一个服务。angularJS服务没有叫
<script>
var module = angular.module("myapp", []);
module.service('BrandService', function ($http) {
var brands = [];
this.getBrands = function()
{
return $http.get('http://admin.localhost/cgi-bin/brand.pl')
.then(function(response)
{
brands = response.brands;
alert (brands);
});
}
//simply returns the brands list
this.list = function()
{
return brands;
}
});
module.controller("brandsController", function($scope, BrandService) {
$scope.brandlist = BrandService.list();
alert ($scope.brandlist);
});
</script>
声明“alert(brands);”没有被调用。这段代码有什么问题。 m是否在执行中缺少任何东西?
警报是空的或不提醒? – 2014-11-24 15:01:39
不在服务中提醒并在控制器中提醒空。 – 2014-11-24 15:04:08
打开调试控制台,告诉我们错误信息是什么。 – 2014-11-24 15:06:33