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(); }]); 我正在尝试使用“服务”但导致错误: 怎么了? 解决方法
您必须更新您的注入以将其传入,因为您正在使用数组表示法:
更改 app.controller('listCtrl',function (situacao,$http) 至 app.controller('listCtrl',['situacao','$scope',$http) { (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |