Not sure what you are trying to do, but something like this should be enough if you use ngAfterViewInit and ElementRef :
import {AfterViewInit, ElementRef} from '@angular/core'; @Component({ selector: 'my-comp', host: ???, template: ` <ng-content></ng-content> ` }) export default class MyComp implements AfterViewInit { @Input() title: string; public isChanged: boolean; constructor(private _ref: ElementRef) {} ngAfterViewInit() { var host = this._ref.nativeElement; if (this.isChanged) { host.style.width = '200px'; } } }
If you want to do some checking for isChanged every time it changes, you can implement ngDoCheck instead:
ngDoCheck() { if (this.isChanged !== this.previousIsChanged) { var host = this._ref.nativeElement; if (this.isChanged) { host.style.width = '200px'; } } }
source share