0

I'm getting some error messages when I try to run my app. I'm not sure what they mean. I'm getting the error Uncaught ReferenceError: accountInfoController is not defined and Uncaught ReferenceError: accountInfoService is not defined.

This is my controller:

(function () {

'use strict';

angular
  .module('crm.ma')
  .controller('accountInfoController', accountInfoController);

accountInfoController.$inject = ['accountInfoService', 'toastr', '$scope'];

function getAccountInfo() {
    accountInfoService.getAccountInfo().then(function (response) {
        if (response.error) {
            toastr.error(response.error);
        }
        else {
            vm.details = response;
        }
    })       
}  
}());

here's my service

(function () {

angular
.module('crm.ma')
.service('accountInfoService', accountInfoService);

accountInfoService.$inject = ['$http', 'apiUrl'];


function getAccountInfo() {
    return $http.get(apiUrl + 'GetAccountDetails')
    .then(function (response) {
        return response.data;
    }, function (response) {
        return { error: response.data.message }
    });
}
}());

Does it have something to do with my router?

    .state('index.DetailsTest', {
             url: '/details',
             templateUrl: 'app/components/main/account/account-details/DetailsTest.html',
             controller: 'accountInfoController',
             data: {
                 pageTitle: 'Test'
             }

         })

1 Answer 1

1

you haven't actually defined the functions for your controller accountInfoController and accountInfoService. You've just defined the methods that should be inside the controller and service

Your code for your controller should look something like:

(function () {

'use strict';

angular
  .module('crm.ma')
  .controller('accountInfoController', accountInfoController);

accountInfoController.$inject = ['accountInfoService', 'toastr', '$scope'];
function accountInfoController(accountInfoService, toastr, $scope) {

  var vm = this;
  vm.getAccountInfo = getAccountInfo
  function getAccountInfo() {
    accountInfoService.getAccountInfo().then(function (response) {
        if (response.error) {
            toastr.error(response.error);
        }
        else {
            vm.details = response;
        }
    })       
  }  

}
}());

and something similar for your service

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Peter Elliott. Thank you for your help. My controller works perfectly now. I'm not sure how the service should be though?
same thing, wrap the service in a function named accountInfoService
Ok! I think I got it. Thanks for your help. Now to figure out the next error message. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.