gpt4 book ai didi

javascript - 无法读取未定义的属性 get Riders

转载 作者:行者123 更新时间:2023-11-28 18:01:12 25 4
gpt4 key购买 nike

我想调用我在 DeliverService 中定义的服务,但是当我从 Controller 调用它时,它给出了 Cannot read property getRiders of undefined 错误,不知道为什么这发生了:|

DeliverService.js

angular.module('Deliver')
.service('DeliverService', ['$http', '$state', '$resource', '$q', 'SettingService', '$localStorage', "MessageService", function($http, $state, $resource, $q, SettingService, $localStorage, MessageService) {
var service = {
getRiders : function(){
return $http.get("Hero.json");
//return $http.get(SettingService.baseUrl + "api/orders");
} }
return service;
}]);

DeliverCtrl.js

use strict';
angular.module('Deliver').controller('DeliverCtrl',['$scope','$state', "SettingService","DeliverService", function($scope, $state, $ionicModal, MessageService, SettingService,DeliverService) {
$scope.riders = [];
DeliverService.getRiders().then(function(response){
$scope.riders = response.data.data;
}, function(error){
});
}]);

最佳答案

您的依赖项与此处的顺序不匹配。因此,DeliverService 实际上并未注入(inject)。

您的 Controller 代码应如下所示:

angular.module('Deliver').controller('DeliverCtrl', 
['$scope','$state', '$ionicModal', 'MessageService', 'SettingService','DeliverService',
function($scope, $state, $ionicModal, MessageService, SettingService, DeliverService) {
$scope.riders = [];
DeliverService.getRiders().then(function(response){
$scope.riders = response.data.data;
}, function(error){});
}]);

关于javascript - 无法读取未定义的属性 get Riders,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43518128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com