javascript - Using an Angular Directive to Add Class to Host Element -


i learning angular 2. understood how use angular renderer set elementstyle, use angular renderer function

setelementclass(renderelement: any, classname: string, isadd: boolean) : void

my question how can import css class attribute directive ? have convert css class json?, or can somehow add css class @ngmodule ?

render deprecated in favor of render2. updated way of angular 4.x+ use addclass method of renderer2.

example:

import { directive, elementref, renderer2 } '@angular/core';  @directive({   selector: '[mydirective]', }) export class mydirective {    constructor(renderer: renderer2, hostelement: elementref) {     this.renderer.addclass(this.hostelement.nativeelement, 'custom-theme');   } } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -