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

后端 未结 14 1782
感动是毒
感动是毒 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:50

    I got this problem because I had wrapped a controller-definition file in a closure:

    (function() {
       ...stuff...
    });
    

    But I had forgotten to actually invoke that closure to execute that definition code and actually tell Javascript my controller existed. I.e., the above needs to be:

    (function() {
       ...stuff...
    })();
    

    Note the () at the end.

提交回复
热议问题