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
Post a Comment