0

Currently I am using document.getElementById to fetch the exact checkbox that needs to be checked.

Here is the code:

setTimeout(function () {
    this.tradeids = JSON.parse(sessionStorage.getItem('tradeids'));                                     
    var x;          
    for (let objtrade of this.tradeids) {
        x = document.getElementById(objtrade);
        x.checked = true;
    }

    this.programIds = JSON.parse(sessionStorage.getItem('programIds'));
    var y;
    for (let objprogram of this.programIds) {
        x = document.getElementById(objprogram);
        x.checked = true;
    }
}, 100);

}

How can I replace document.getElementbyId with elementRef or any other typescript function.

FYI, I did use elementRef using querySelector but the log says that nativeElement is undefined.

PrakashG
  • 1,642
  • 5
  • 20
  • 30
Pratyush Swain
  • 144
  • 1
  • 9
  • (https://stackoverflow.com/questions/32693061/how-can-i-select-an-element-in-a-component-template) follow this for `elementRef` i thing you need to also go through with `typescript`. last one is why you are using querySelector for checkbox other way is there like template-driven or rectiveForm according to me. – Abhishek Dec 31 '18 at 12:06
  • I tried this but i am not able to get the nodeList. NativeElement is undefined – Pratyush Swain Jan 02 '19 at 07:55

0 Answers0