加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:58:25 所属栏目:安全 来源:网络整理
导读: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
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) {

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读