lundi 31 décembre 2018

How can i use ElementRef instead of document.getElementById to fetch the nodeList

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.




Aucun commentaire:

Enregistrer un commentaire