繁体   English   中英

在自定义角度指令中使用控制器

[英]Using A Controller in a Custom Angular 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',

    }
})

这是我通过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.

我认为这是拼写错误,您的模块名称是myApp,并且在您的代码中编写了:

app.directive('reviewForm', function() {......

它应该是myApp.directive,如下所示:

myApp.directive('reviewForm', function() {
   return {
        restrict: 'E',
        templateUrl: 'partials/review-form.html',
        replace: true,
        controller: function() {
            this.showForm: false;
        },
        controllerAs: 'reviewFormCtrl',

    }
})

如果不起作用,请检查模块名称的拼写。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM