Я использую ионный и angularjs для мобильного приложения, я пытаюсь использовать тянуть, чтобы обновить, но когда обновление (вызов doRefresh из UI) происходит, я получаю сообщение об ошибкеFactory возвращающего неопределенный объект
«Uncaught TypeError: не удается прочитать свойство„getFromServer“неопределенных»
вызов getServiceList работает нормально, когда контроллер становится загружен
Я не могу понять, почему serviceListSerice возвращается неопределенный объект. Пожалуйста, помогите
Моего Controller.js
angular.module('starter.controllers', ['ionic', 'ui.bootstrap.datetimepicker'])
.controller('serviceListCtrl',function($scope,$rootScope,$state,serviceListService){
$scope.doRefresh=function(serviceListService,$scope) {
serviceListService.getFromServer($scope); //<-this is where i am getting the error
//$scope.$broadcast('scroll.refreshComplete');
};
serviceListService.getServiceList($scope); //<--- this is called successfully
//when controller is getting loaded.
})
Моего services.js
angular.module('starter.services', [])
.factory('serviceListService',function() {
return {
getServiceList : function($scope) {
var jsonStr='({"data":[{"id":"1","CircuitID":"130101002","Customer No.":"4160891","CustomerName":"ZZZZ Customer","Last Order":"130101002","ServiceType":"Some String","StartDate":"41878.4125"},'+
'{"id":"2","CircuitID":"140501837","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140501837","ServiceType":"SOME STRING","StartDate":"41859.4083333333"},'+
'{"id":"3","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"4","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"5","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"6","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"7","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"8","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"9","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"10","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"11","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"12","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"13","CircuitID":"140502362","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"}'+
']})';
console.log(jsonStr);
var datas= eval(jsonStr);
$scope.services=datas.data;
},
loadMoreServices : function($scope) {
var updateList='({"data":[{"id":"14","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"15","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"16","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"17","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"18","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"19","CircuitID":"140502362","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"}'+
']})';
$scope.res.push(eval(jsonStr));
$scope.$broadcast('scroll.infiniteScrollComplete');
},
getFromServer:function($scope) {
var jsonStr='({"data":[{"id":"14","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"15","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"16","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"17","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"18","CircuitID":"140502361","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"},'+
'{"id":"19","CircuitID":"140502362","Customer No.":"A0156272","CustomerName":"SOME Company","Last Order":"140502361","ServiceType":"SOME STRING","StartDate":"41858.9583333333"}'+
']})';
$scope.res= eval(jsonStr);
$scope.$broadcast('scroll.refreshComplete');
},
clearSearch : function($scope) {
$scope.search = '';
}
}
})
Как вы вызываете метод doRefresh()? .. И вам действительно нужна служба и область применения в качестве аргументов этого метода? – user700284
@ user700284, вы правы, удалив оба параметра для меня. Спасибо за помощь. – Harshit