2 @HostBinding 1 Member in Angular

1188 views angular
7

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

@Input()
@HostBinding('class.form-control')
hasFormControl: boolean = true;

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

@Input()
@HostBinding('class.form-control')
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

2

May be:

_hasFormControl: boolean = true;

@Input()
@HostBinding('class.form-control')
get classFormControl() { return this._hasFormControl; }
@HostBinding('class.px-0')
get classPx0() { return this._hasFormControl; }

posted this

Have an answer?

JD

Please login first before posting an answer.