[英]Using A Controller in a Custom Angular Directive
I've been following along with a codeschool Angular tutorial and my app works fine until adding this custom directive: 我一直在遵循Codeschool Angular教程,在添加此自定义指令之前,我的应用程序可以正常运行:
// Breaks here
app.directive('reviewForm', function() {
return {
restrict: 'E',
templateUrl: 'partials/review-form.html',
replace: true,
controller: function() {
this.showForm: false;
},
controllerAs: 'reviewFormCtrl',
}
})
And here is the error I receive via console.log: 这是我通过console.log收到的错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled
the module name or forgot to load it. If registering a module
ensure that you specify the dependencies as the second argument.
I think it is spelling mistake, your module name is myApp, and in your code you wrote: 我认为这是拼写错误,您的模块名称是myApp,并且在您的代码中编写了:
app.directive('reviewForm', function() {......
it should be myApp.directive , like this: 它应该是myApp.directive,如下所示:
myApp.directive('reviewForm', function() {
return {
restrict: 'E',
templateUrl: 'partials/review-form.html',
replace: true,
controller: function() {
this.showForm: false;
},
controllerAs: 'reviewFormCtrl',
}
})
if it did not work, check the spelling of your module name. 如果不起作用,请检查模块名称的拼写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.