【发布时间】:2018-07-14 16:24:37
【问题描述】:
我有一个需要做一些 DOM 操作的小助手类。我试图在this 和其他一些人之后使用 ViewChild() 但它无法编译。我猜 ViewChild() 需要 @Component 指令才能工作?
我现在的班级是:
@Injectable()
export class calculator {
constructor(){}
calculate(calling_btn:string){
//while a rather longish calcualtion is done, I need to disable the specific btn that called the calculate method. then display the result.
@ViewChild(calling_btn) ele: ElementRef;
}
html:
<button #stage1 (click)="calculate('stage1')">Stage 1</button>
最多可以有 15 个按钮请求计算,我想禁用每个请求计算然后返回结果的按钮。它正在工作,但有时用户多次单击一个按钮,我想停止它。
如果我使用 getElementById 效果很好,但我读到它不是一个好习惯。有什么想法吗?
【问题讨论】:
-
试试
setTimeOut -
谢谢。可以多加几个字或者链接吗?
-
查看此链接Demo 以获得更好的理解