0

I have just created a simple app. Route for main controller is working but not for another one. This is the part of the code of route file

$routeProvider
  .when('/', {
    templateUrl: 'app/main/main.html',
    controller: 'MainController',
    controllerAs: 'main'
  })
  .when('/signatures', {
    templateUrl: 'app/components/signature/signature.html',
    controller: 'SignatureController',
    controllerAs: 'signature',
    resolve: {
      signatureLists: function(SignatureService){
        return SignatureService.getSignatures();
      }
    }
  })
  .otherwise({
    redirectTo: '/'
  });

and below is the controller

(function() {
  'use strict';

  angular
    .module('demoapp')
    .controller('SignatureController', SignatureController);

  /** @ngInject */
  function SignatureController(signatureLists) {
    var vm = this;
    vm.signatures = signatureLists;
  }
})

I have defined the module in another file:

(function() {
  'use strict';

  angular
    .module('demoapp', ['ngRoute', 'toastr']);

})();

when I try to visit /signatures page, I get this error:

Error: [ng:areq] Argument 'SignatureController' is not a function, got undefined

Maybe its just a silly error due to a typo or something else but still I can't figure it out

3
  • You forgot to self invoke the controller closure..do a () at the end Commented Aug 20, 2016 at 6:57
  • check whether you added that script in your html <script src= " ...." > Commented Aug 20, 2016 at 6:57
  • As you have defined both your module and controller in different files, you will have include both .js files. Commented Aug 20, 2016 at 6:59

1 Answer 1

1

You forgot to self invoke the controller closure..do a () at the end

(function() {
 'use strict';

 angular
 .module('demoapp')
 .controller('SignatureController', SignatureController);

 /** @ngInject */
 function SignatureController(signatureLists) {
  var vm = this;
  vm.signatures = signatureLists;
 }
})()
Sign up to request clarification or add additional context in comments.

2 Comments

I knew this would be something like this. Thanks for the help.
@sajan - no probs, I have done this mistake 100 times :)

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.