document.getElementById replacement in angular4 / typescript?

后端 未结 5 759
刺人心
刺人心 2020-11-29 03:10

So, im working with angular4 in my practice work and this is new for me. Luckyly, in order to get html elements and its values i used documen

5条回答
  •  借酒劲吻你
    2020-11-29 03:59

    For Angular 8 or posterior @ViewChild have an additional parameter called opts, which have two properties: read and static, read is optional. You can use it like so:

    // ...
    @ViewChild('mydiv', { static: false }) public mydiv: ElementRef;
    
    constructor() {
    // ...
    

    NOTE: Static: false is not required anymore in Angular 9. (just { static: true } when you are going to use that variable inside ngOnInit)

提交回复
热议问题