0

Yet another troubling situation with a new project:

Following controller code:

(function () {
'use strict';

angular
    .module('offerRequest', [])
    .controller('offerRequestCtrl', offerRequestCtrl);

offerRequestCtrl.$inject = ['$scope', '$rootScope', '$location'];

function offerRequestCtrl($scope, $rootScope, $location) {
    // controller code starts here.

    /* jshint validthis:true */
    var vm = this;
    vm.title = 'offerRequestCtrl';

    activate();

    function activate() { }
}
})();

With the following routing:

  // state for requesting offers
    .state('offerrequest', {
        url: '/offerrequest',
        templateUrl: 'app/components/offerrequest/offerrequest.html',
        controller: 'offerRequestCtrl'
    })

Causes the following error message:

   Argument 'offerRequestCtrl' is not a function, got undefined

Tried the older style of defining it:

   angular.module('offerRequest', [])
    .controller('offerRequestCtrl', function offerRequestCtrl() {

    });

Throws the same error. What could I be doing wrong in the first implementation which I would like to work with?

poptard
  • 61
  • 1
  • 10
  • 2
    have you used `.module('offerRequest', [])` somewhere else? – Satpal Mar 08 '17 at 15:40
  • Could you provide a plunkr or jsfiddle ? – vjarysta Mar 08 '17 at 15:41
  • @satpal yes I have, in another service I'm using. Is that uncorrect way? I removed the service and it's still throwing the same error. – poptard Mar 08 '17 at 15:42
  • `(function () { 'use strict'; angular .module('offerRequest', []) .factory('offerRequestService', offerRequestService); offerRequestService.$inject = ['$location']; function offerRequestService($location) { // controller code starts here. /* jshint validthis:true */ var vm = this; vm.title = 'offerRequestService'; activate(); function activate() { } } })(); ` – poptard Mar 08 '17 at 15:43
  • Possible duplicate of [Error: $controller:ctrlreg The controller with the name '{0}' is not registered](http://stackoverflow.com/questions/42512892/error-controllerctrlreg-the-controller-with-the-name-0-is-not-registered) – Satpal Mar 08 '17 at 15:44
  • 1
    You can only define module once – Satpal Mar 08 '17 at 15:45
  • It seems without declaring dependencies I can use the module in the service aswell. Thanks alot for your input, @Satpal – poptard Mar 08 '17 at 15:47

1 Answers1

2

You need to have the module declared with dependencies only globally,

angular
    .module('offerRequest', [])

Change your controller as,

angular
    .module('offerRequest')
    .controller('offerRequestCtrl', offerRequestCtrl);
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396