Exocomp
Exocomp

Reputation: 1537

angular2 HostBinding with an Input property

Is it possible to set the HostBinding with an Input property. If not what is your approximate solution?

For Ex:

Directive:

  @Input('customToggle') target;
  private toggle = false;

  @HostBinding(target) 
  get getToggle() {
    return this.toggle;
  }

View:

  <li class="dropdown" [customToggle]="class.open">

Note how HostBinding has target passed as an argument, how can this be accomplished?

Upvotes: 2

Views: 736

Answers (1)

Mattew Eon
Mattew Eon

Reputation: 1783

You can do it this way :

@HostBinding(target) toggle: boolean = false;
@Input('customToggle') set target(toggle: boolean) {
   this.toggle = toggle;
}

Upvotes: 1

Related Questions