Angular: Controller is undefined when adding a directive

前端 未结 2 2012
被撕碎了的回忆
被撕碎了的回忆 2021-01-23 00:12

I get the following error when adding a directive to my site:

Error: [ng:areq] Argument \'MainController\' is not a function, got undefined

The

2条回答
  •  暖寄归人
    2021-01-23 01:09

    passing a 2nd argument like this angular.module('my-app', []) creates a new module, use it only once.

    To retrive a module use var module = angular.module('my-app') and use module.controller(... or module.directive(.... etc.,

提交回复
热议问题