Я получаю «не является функцией» Ошибка при вызове метода Factory из контроллера в angular.js - PullRequest
0 голосов
/ 22 марта 2019

Я пытаюсь вызвать фабричный метод в angular.js из моего метода контроллера, и он выдает ошибку «не является функцией»

Вот как выглядит фабрика:

function getData($q) {
  var getMessages = function(id) {
    var deferred = $q.defer();
    // deferred.notify('About to greet ' + name + '.');
    GTS2_FIN_MU_Dist_Pct_Controller.getUltimates(
      id,
      function(result, event) {
        if (event.status) {
          //      console.log(result);
          var obj = JSON.parse(result);
          deferred.resolve(obj);
        } else {
          deferred.reject("Error Processing the Request :  " + event.message);
        }
      },
      { escape: false }
    );
    return deferred.promise;
  };
  return {
    getMessages: getMessages,
  };
}

app.factory("getData", getData);

Контроллер выглядит так:

app.controller("intlMassUpdateDistPctController", function($scope) 
        { // define angular controller
        $scope.ultimates = new Array; // define empty array to hold ultimate versions from VF remote action
        // Calls controller method Remote Action and passes the ultimateId, and handles the result by storing it inside $scope.ultimateVersions
        $scope.loadData = function(){
            //$j214('#dialogNew').show();
            var promise = getData.getMessages('');  //Calling factory method.. This is where U get the error
            promise.then(function(obj) {
            $scope.selectedForecastLocked = false;
            var JSONdata = JSON.parse(obj);
            $scope.ultimates = JSONdata.Ultimates;
            $scope.gridOptions.api.setRowData($scope.ultimates);
                    ........
            }, function(reason) {
                        alert('Failed: ' + reason);
                    }, function(update) {
                        alert('Got notification: ' + update);
                    });
            }
        });     

Я также определил приложение.

var app = angular.module('intlMassUpdateDistPct', ['agGrid','ui.bootstrap']);

И наконец:

<body ng-app="myApp" >
<div ng-controller="intlMassUpdateDistPctController">

Может кто-нибудь, пожалуйста, помогите мне определить, что отсутствует.

1 Ответ

0 голосов
/ 22 марта 2019

Попробуйте ввести getData фабрику в контроллер:

app.controller("intlMassUpdateDistPctController", function($scope,getData){
   // your code...
}) 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...