Conditional @HostBinding depending on @Input()
What you did is almost correct :
export class MyComponent {
@Input()
public input: string;
@HostBinding('class.foo')
public get isFoo(): Boolean {
return this.input !== 'not correct';
}
}
Try this way. Make @Input property getter/setter and set the isFoo
from the setter.
export class MyComponent {
@Input()
public get input (): string {
return this._input;
}
public set input (val: string) {
this._input = val;
// when the input is set check it and set isFoo;
this.isFoo = (val != 'not correct');
}
@HostBinding('class.foo')
public isFoo: Boolean = false; // false is init value
constructor() {
}
}