Angular set css style for :host in ngOnInit -


i don't know how set css style :host {} in ngoninit in component. can use renderer set this?

example:

<app-a *ngfor ="let in alist" [a] = "a"></app-a> 

in ngoninit app-a wanna set width height style percent :host of app-a component when in rendered ngfor?

can it?

many thanks.

you set styles in declarative way in component decorator:

@component({    styles: [':host { display: block; }'] }); export class appcomponent {} 

but if need ngoninit, can insert host element , use renderer:

export class appcomponent {   constructor(private host: elementref, private renderer: renderer2) {  }    ngoninit() {     this.renderer.setstyle(this.host.nativeelement, 'display', 'block');   } 

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 -