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

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

    I had this error because I didn't understand the difference between angular.module('myApp', []) and angular.module('myApp').

    This creates the module 'myApp' and overwrites any existing module named 'myApp':

    angular.module('myApp', [])

    This retrieves an existing module 'myApp':

    angular.module('myApp')

    I had been overwriting my module in another file, using the first call above which created another module instead of retrieving as I expected.

    More detail here: https://docs.angularjs.org/guide/module

提交回复
热议问题