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

Multi tool use
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.
angular checkbox nodelist elementref
add a comment |
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.
angular checkbox nodelist elementref
(stackoverflow.com/questions/32693061/…) follow this forelementRef
i thing you need to also go through withtypescript
. 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 2 at 7:55
add a comment |
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.
angular checkbox nodelist elementref
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.
angular checkbox nodelist elementref
angular checkbox nodelist elementref
edited Dec 31 '18 at 12:52


PrakashG
814719
814719
asked Dec 31 '18 at 11:48


Pratyush SwainPratyush Swain
41
41
(stackoverflow.com/questions/32693061/…) follow this forelementRef
i thing you need to also go through withtypescript
. 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 2 at 7:55
add a comment |
(stackoverflow.com/questions/32693061/…) follow this forelementRef
i thing you need to also go through withtypescript
. 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 2 at 7:55
(stackoverflow.com/questions/32693061/…) 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
(stackoverflow.com/questions/32693061/…) 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 2 at 7:55
I tried this but i am not able to get the nodeList. NativeElement is undefined
– Pratyush Swain
Jan 2 at 7:55
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987131%2fhow-can-i-use-elementref-instead-of-document-getelementbyid-to-fetch-the-nodelis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987131%2fhow-can-i-use-elementref-instead-of-document-getelementbyid-to-fetch-the-nodelis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
mUIfAP60A 8YLSYcB0pXAHM z6JWHP2c7Nm5gv2G6Yvo4 Uzm3neGR,85aT Wv7Meqch F3qnaNJWWksErOJ9kxz,M,1f38MvmlHRyHT
(stackoverflow.com/questions/32693061/…) follow this for
elementRef
i thing you need to also go through withtypescript
. 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 2 at 7:55