Get DOM element which is a component in Angular -


i read answers here, such this, problem different. want component dom element can add/remove css classes on it.

my html template contains component:

<sidenav-menu #sidenav class="app__sidenav"></sidenav-menu>

and class contains reference it:

@viewchild('sidenav') sidenav: elementref; 

but when log this.sidenav in 1 of functions, see representation of class of sidenav component, not dom representation. why happening?

you can specify want using read parameter:

@viewchild('sidenav', {read: elementref}) sidenav: elementref; 

this way elementref , can use this.sidenav.nativeelement mentioned @joshrathke

or (for other use cases)

@viewchild('sidenav', {read: viewcontainerref}) sidenav: elementref; 

my answer question liked mentions read parameter https://stackoverflow.com/a/35209681/217408


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -