Angular: Controller is undefined when adding a directive

前端 未结 2 2011
被撕碎了的回忆
被撕碎了的回忆 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:08

    You are redefining the module. Define module only once.

    when used as angular.module('my-app', []) it defined the module this should be used only once. When you want retrieve it. then use angular.module('my-app')

    Use

    angular.module('my-app')  //Notice remove []
      .directive("welcome", function() {
      });
    
    0 讨论(0)
  • 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.,

    0 讨论(0)
提交回复
热议问题