0
我一直在學習Angular2。我觀察到'指令'標籤在RC版本的@Component元數據中用於引用其中的另一個組件。但是在Ang 2.1.0版中沒有與它相關的'指令'標籤。我現在應該如何引用另一個組件?Angular2中指令的替換是什麼?
我一直在學習Angular2。我觀察到'指令'標籤在RC版本的@Component元數據中用於引用其中的另一個組件。但是在Ang 2.1.0版中沒有與它相關的'指令'標籤。我現在應該如何引用另一個組件?Angular2中指令的替換是什麼?
你應該申報declarations
的@NgModule
元財產directives
,如下圖所示(如directives
元物業已經從@Component
裝飾去掉)
@NgModule({
imports : [ BrowserModule, .... ],
declarations : [
AppComponent,
DashboardComponent //<<<### here it is another component or directive,
HighlightDirective //<<<### directive declared with @Directive decorator
],
providers : [ ],
bootstrap : [ AppComponent ]
})
export class AppModule { }
以獲得更多信息可以參考https://angular.io/docs/ts/latest/guide/ngmodule.html
非常感謝micronyks的迴應,但這是唯一的方法嗎?我不能在組件內使用標籤進行引用嗎?我看到在@Component內部有一個'entryComponent'標籤,但它不像指令那樣工作。請澄清。 –
entryCompoent在您想要動態注入組件時使用。但對於靜態cmp你可以用圖示的方式去... – micronyks
謝謝micronyks! –