簡體   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