2 @HostBinding 1 Member in Angular

1188 views angular

I Use the following to default a bootstrap class when my component is used. It works perfectly well (angular 6):

hasFormControl: boolean = true;

However i want to configure other HostBindings to apply on when the same variable is true, somewhat like this:

hasFormControl: boolean = true;
@HostBinding('class.px-0') this.hasFormControl; // does not compile

How to properly do this?

answered question

why do you want to access two properties by one variable ?

convenience. Of course i would then rename it to reflect whats being done when setting it.

1 Answer


May be:

_hasFormControl: boolean = true;

get classFormControl() { return this._hasFormControl; }
get classPx0() { return this._hasFormControl; }

posted this

Have an answer?


Please login first before posting an answer.