[英]How i can use differents html template for the same typescript file?
我需要使用不同的html模板作為相同的typescript文件,基於我的構造函數中的表達式。 這個有可能?
我需要這樣的東西:
<div class="container-fluid">
<app-teste1 *ngIf="teste == '1'>
<app-teste2 *ngIf="teste == '2'>
</div>
並在構造函數中:
this.teste = 1
因此必須重新定義第一個組件(app-teste1)。
但是我的組件有很多屬性,還有其他方法可以在不通過各種輸入/輸出屬性的情況下進行此操作嗎?
我不認為現在有角度( angular 8.0.0-beta.13
)。
您可以以多種不同的方式操作和呈現DOM樹,但是現在無法在角度中加載不同的模板( .html
)文件。
您可以從基類繼承並使用其他模板。 像這樣的東西:
@Component({
selector: 'app-teste1',
template: `<div>this is app-teste1</div>`
})
export class TestOneComponent {
// ...
}
@Component({
selector: 'app-teste2',
template: `<div>this is app-teste2</div>`
})
export class TestTwoComponent extends TestOneComponent {
// ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.