0

I have tried creating a controller using meanjs.org. The controller is working fine with the other existing controllers but it is not working fine with new one I have created, Help would be appreciated, Thank you.

angular.js:12808 Error: [ng:areq] Argument 'TestownerControllerController' is not a function, got undefined http://errors.angularjs.org/1.4.14/ng/areq?p0=TestownerControllerController&p1=not%20aNaNunction%2C%20got%20undefined

this is my controller code

(function() {
  'use strict';

  angular.module('users').controller('TestownerControllerController', TestownerControllerController);

  TestownerControllerController.$inject = ['$scope'];

  function TestownerControllerController($scope) {
    var vm = this;

    // Testowner controller controller logic
    // ...

    init();

    function init() {
    }
  }
})();
5
  • Share your code Commented Jun 28, 2018 at 5:14
  • I have created that using yo generator in meanjs.org, existing controllers are working fine, but new controller is not working Commented Jun 28, 2018 at 5:14
  • @vishuminhas please check I have shared the code Commented Jun 28, 2018 at 5:18
  • Quick response would be appreciated greatly Commented Jun 28, 2018 at 5:39
  • use strict prevents you from using functions before they are declared. Change the order and put the TestownerControllerController-function above the other two lines (which are trying to use it). Commented Jun 28, 2018 at 5:45

1 Answer 1

0

In your case you miss [] where you define user app angular.module('users')...

[]: it's required and we use it to inject other modules.

also you can set a config in your app like this:

app.config(["$controllerProvider", "$compileProvider", "$filterProvider", "$provide", function ($stateProvider, configs, $controllerProvider, $compileProvider, $filterProvider, $provide) {
app.controller = $controllerProvider.register;
app.directive = $compileProvider.register;
app.filter = $filterProvider.register;
app.factory = $provide.factory;
app.service = $provide.service;
app.constant = $provide.constant;
}]);

This config help you to register a module with others dependencies.

//our main app
var app = angular.module('users', [])

//our controller
function testController($scope) {
    function init() {
        //somthing
    }
    init();
}

testController.$inject = ['$scope'];
app.controller('testController', testController);
Sign up to request clarification or add additional context in comments.

Comments

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.