1

I have a component that I needs to be hidden when a property is true. Is there a way to solve this within the component itself.

Example:

@Component({
  selector: 'prio-tab',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template:
  `
      <div [hidden]="!active">
        stuff
      </div>
    `
})

export class PrioTabComponent {
  @Input() title;
  active:boolean = false;
}

Here I would like to have the actual "prio-tab" element to depend on active-flag. Not just the content inside prio-tab.

Or is it maybe possible to use itself when declaring the prio-tab tag, like this:

<prio-tab [hidden]="this.active">
     stuff
</prio-tab>

I guess a working solution would be to create a reference to the prio-tab component in its parent and then go through the parent. But how would I do if I have multiple prio-tab's ?

1 Answer 1

1

You can use @HostBinding()

export class PrioTabComponent {
  @Input() title;

  @HostBinding('hidden')
  active:boolean = false;
}
Sign up to request clarification or add additional context in comments.

1 Comment

That is bloody marvelous !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.