[英]Angular Structural Directive Broken
我正在嘗試使用Angular 5.2.9創建一個網站。 我正在構建一個用於登錄的系統,現在想避免在未授權用戶的情況下將元素加載到頁面中。
路由是一回事,我可以使用canActivate並將AuthGuard放在其中,但是對於特定元素(如菜單項,頁面元素),我想控制用戶是否看到它們。 因此,我認為我將創建一個結構性指令。
我將示例代碼直接從Angular文檔復制到了我的應用程序中。 鍵入時出現錯誤;
屬性綁定app除非嵌入式模板上的任何指令均未使用。 確保屬性名稱拼寫正確,並且所有指令均在“ @ NgModule.declarations”中列出。
我在app.module.ts中的聲明中引用了指令。 我確定我缺少了一些東西,但是我不確定。 我到處都看過了。
我從下面的angular documentation
中復制並粘貼了app.module.ts文件。
您忘記在項目中添加declarations: [UnlessDirective]
。 這就是您收到錯誤的原因。 UnlessDirective
將指令替換為您的指令名稱。
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { heroSwitchComponents } from './hero-switch.components';
import { UnlessDirective } from './unless.directive';
@NgModule({
imports: [ BrowserModule, FormsModule ],
declarations: [
AppComponent,
heroSwitchComponents,
UnlessDirective
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.