2016-10-12 83 views
0

我的模板是從Java層驅動的複雜規則動態派生的。動態設置@Component模板

有沒有辦法在ngOnInit上動態設置或更新組件的模板?

+0

你可以檢查這個答案http://stackoverflow.com/questions/39782409/angular-2-stable-templateurl-variable或這個http://stackoverflow.com/questions/39410355/how-to-use-variable -to-define-templateurl-in-angular2 – yurzui

+0

yurzui - 模板綁定如何在新創建的組件中工作?這兩個例子都很接近 - 除了我需要新創建的組件有理想的輸入和輸出從父組件。 – user1143933

回答

0

Angular2允許組件的模板指向一個文件。

@Component({ 
    selector: 'mycomponent', 
    templateUrl: 'views/mycomponent.html' 
}) 

您可以改爲指向動態生成的頁面。