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 -

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' -