3 回答

TA貢獻1880條經驗 獲得超4個贊
通過注入?DocumenttableData?是否存在> 將令牌放入構造函數中。接下來,使用普通的舊 JavaScript 通過 id 查找元素。視圖加載后,檢查它是否存在,如下所示:
import { Inject } from "@angular/core";
import { DOCUMENT } from "@angular/common";
constructor(@Inject(DOCUMENT) document) {
}
ngAfterViewInit() {
? ?if (document.getElementById('tableData')) {
? ? ? // success scenario
? ?} else {
? ? ? // failure
? ?}
}
ngOnInit() {
? ?generateTableDataAfterDOMIsReady('#container');
}
將?generateTableDataAfterDOMIsReady('#container');
?的調用移至 ngOnInit 而不是 ngAfterViewInit 中。
@ViewChild
?會更好,但僅當標記的 id 指定為?#id
?時才有效。

TA貢獻1805條經驗 獲得超10個贊
最簡單的方法是設置一個標志
ngAfterViewInit() {
//Run a library that will populate the table, for example
//This will create an element with an id tableData
generateTableDataAfterDOMIsReady('#container');
this.pseudoIsTableDataExists=true
}
和
<div *ngIf="pseudoIsTableDataExists">Data has been generated</div>

TA貢獻1856條經驗 獲得超17個贊
簡單地說,您可以綁定hidden 屬性。
超文本標記語言
<div [hidden]="!isTableDataExists">
Data has been generated
</div>
成分
ngAfterViewInit() {
//Run a library that will populate the table, for example
//This will create an element with an id tableData
generateTableDataAfterDOMIsReady('#container');
this.isTableDataExists = true;
}
- 3 回答
- 0 關注
- 199 瀏覽
添加回答
舉報