Angular: Controller is undefined when adding a directive

前端 未结 2 2040
被撕碎了的回忆
被撕碎了的回忆 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() {
      });
    

提交回复
热议问题