Hi all ! Could anyone suggest please right way to select current element in DOM. When I have two the same page in stack, document.getElementById always select first element. How to select necessary element form necessary page… not always first element ?
Why do you want to do that?
Normally you don’t interact directly with the DOM in Angular apps.
Sujan12, when I have in Ionic something like this …
<ion-grid id="grid>
<ion-row>
<ion-col> </ion-col>
</ion-row>
</ion-grid>
And add this page in stack several times … document.getElementById(‘grid’) return only first page with id="grid … not necessary page … this is my problem … because in stack we could see more then one grid with id="grid.
Why can’t you just use ViewChild?
AaronSterling, thanks, I solved problem with adding stack index to id.
That’s not the solution. You should never be directly interacting with the DOM like you are in an Angular app.
rapropos, good day ! Could you suggest how to do right ?
Not given what you’ve said so far, because you haven’t described the actual overall goal. What are you wanting to do with this element once you’ve got it?
The other guys here are 100% correct.
You shouldn’t ever need to interact with the Dom in that manner.
Your form should react to your model, and only when required you can use viewchild to manipulate elements eliminating the need to use id’s.
If you’re making a component for example and you wish to use it several times on a single page it’s more difficult to do in your fashion.
rapropos,codiqa100031834,thanks for replay.