假设我有一个父组件app-main-console
和一个嵌套组件app-console
。嵌套组件有一个表。当主要组件加载时它是初始的。
如果用户想要查看它,我希望获取数据来填充表。所以有一个input
属性叫做fetchTableData
.
<app-console [fetchTableData]="fetchTableData">
</app-console>
这是一个布尔值。
@Input() fetchTableData: boolean;
是否可以定义一个事件,以便当 的值fetchTableData
变为 时true
,我可以调用后端服务?
谢谢你的帮助
您可以使用OnChanges
from Angular 生命周期 hook。
ngOnChanges(changes: SimpleChanges) {
for (let propName in changes) {
if(propName === 'fetchTableData') {
let chng = changes[propName];
let cur = chng.currentValue;
let prev = chng.previousValue;
if(cur && cur === true) {
// Action you want to perform
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句