我有两个组件,子组件显示状态由父级控制。如何让孩子知道它的父元素是否改变了隐藏属性?
// 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?
}
答案 0 :(得分:1)
该组件需要一个名称匹配的[xxx]="..."
来支持@Component(selector: '[component-child]',
templateUrl: 'component-child.html')
class ComponentChild {
@Input()
set hidden(bool val) {
print(val);
}
}
绑定:
{{1}}