【发布时间】:2019-05-05 11:07:33
【问题描述】:
我注意到以下绑定似乎对 set 属性产生了正确的行为,但在设置值时没有被调用。
<input (keyup)="onKeyUp()" value={{config.rendition}}>
export class RowConfig {
constructor(public amount = 0, ... ) { }
get rendition() { return this.amount + "$"; }
set rendition(input: string) {
console.log("setter with '" + input + "' invoked");
const numeric = input.replace("$", "");
this.amount = +numeric;
}
}
keyup 按预期执行,但rendition 的设置器不会向控制台打印任何内容,所以我假设它没有正确绑定和/或根本不可绑定。
我松散地关注stuff like this,并且我有一个Blitzy 可以玩的行为。
由于input 作为标签和@Input 作为装饰器之间的冲突,谷歌搜索有点困难。后者到目前为止赢了......不过,我收集的是使用[(ngModel)] 绑定或使用指令或管道。所有的线索在相关性和/或可靠性方面似乎都有点不确定。因此,StackBlitz 上的演示。
【问题讨论】:
-
onKeyUp的方法在哪里? -
@wentjun 在组件中使用配置类作为@Input。类 EditableRowComponent 在第 18 行。
标签: angular data-binding