【发布时间】:2017-10-05 15:35:01
【问题描述】:
家长
HTML
<tr
[onTotalWeights]="totalWeights"
>
代码
totalWeights(): number {
return // Get sum of fields over the whole array
}
儿童
@Input() onTotalWeights: () => number;
canApplyChanges() {
return this.onTotalWeights() <= 100 && this.form.valid;
}
我想从子级调用父级的方法并返回一个值。
目前的问题是,在子组件中 this.onTotalWeights() 被称为“this”关键字时是指子组件内部的方法/变量,而不是来自父组件。当我传递 totalWeights 函数时,上下文不知何故丢失了。
我该如何解决这个问题?
【问题讨论】:
标签: javascript angular typescript ecmascript-next