Controller not a function, got undefined, while defining controllers globally

后端 未结 14 1773
感动是毒
感动是毒 2020-11-22 00:22

I am writing a sample application using angularjs. i got an error mentioned below on chrome browser.

Error is

Error: [ng:areq] http://errors.

14条回答
  •  清酒与你
    2020-11-22 00:38

    If you're using routes (high probability) and your config has a reference to a controller in a module that's not declared as dependency then initialisation might fail too.

    E.g assuming you've configured ngRoute for your app, like

    angular.module('yourModule',['ngRoute'])
    .config(function($routeProvider, $httpProvider) { ... });
    

    Be careful in the block that declares the routes,

    .when('/resourcePath', { 
    templateUrl: 'resource.html',
    controller: 'secondModuleController' //lives in secondModule
    });
    

    Declare secondModule as a dependency after 'ngRoute' should resolve the issue. I know I had this problem.

提交回复
热议问题