angularjs – 角度服务不是函数错误

前端之家收集整理的这篇文章主要介绍了angularjs – 角度服务不是函数错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
app.service('situacao',function($log,$q,$http,$rootScope){
var situacao = this; 
situacao.lista = {};
situacao.getAllSituacao = function(){
    var defer = $q.defer();
    console.log("PHP/getAll.PHP");
    $http.get($rootScope.endPoint + "PHP/getAll.PHP")
        .success(function(res) {
        console.log(res);
        situacao.lista = res;
        defer.resolve(res);
    }).error(function(err,status){
        defer.reject(err);
    }); 
    return defer.promise;
};
return situacao;});
app.controller('listCtrl',['$scope','$uibModal','$log','$http',function(situacao,$scope,$modal,$log,$http) {   
$scope.init = function(){
    $scope.getAll();
}
$scope.getAll = function(){        
    situacao.getAllSituacao().then(function(res){
        //sucess
        $scope.dispSituacao = situacao.lista;  
    },function(err){
        //error
    })
};
$scope.init(); }]);

我正在尝试使用“服务”但导致错误
situacao.getAllSituacao不是一个函数.
Nãainconsigo utilizar o service semper mostra a mensagem de erroquenãoéumamação

怎么了?

解决方法

您必须更新您的注入以将其传入,因为您正在使用数组表示法:

更改

app.controller('listCtrl',function (situacao,$http)

app.controller('listCtrl',['situacao','$scope',$http) {

猜你在找的Angularjs相关文章