Roger Chan
Roger Chan

Reputation: 1413

How to let component detect its hidden status in angular2?

I have two components, child component display status is controlling by the parent. How to let child aware its parent is changed the hidden attribute?

// Parnet
@Component(selector: '[component-parent]',
    templateUrl: 'component-parent.html')
class ComponentParent {
    bool enableChild;
}

<div>
    <div component-child [hidden]="enableChild"></div>
</div>

// Child
@Component(selector: '[component-child]',
    templateUrl: 'component-child.html')
class ComponentChild {
    // How child aware not it is not hidden anymore?
}

Upvotes: 2

Views: 802

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657741

The component needs an @Input() with matching name to support [xxx]="..." binding:

@Component(selector: '[component-child]',
    templateUrl: 'component-child.html')
class ComponentChild {
  @Input()
  set hidden(bool val) {
    print(val);
  }
}

Upvotes: 1

Related Questions