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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -