angular - 如何以编程方式更改 @Output() 上的 bindingPropertyName
问题描述
我需要以编程方式更改一个 @Output() 上的 bindingPropertyName。
我使用一个指令在一个聚合物 2.0 组件中的属性(将 reflectToAttribute 设置为 true)和我在 Angular 5 中的应用程序之间进行两种方式绑定。
代码:
@Directive({
selector: "[bindPolymer]"
})
export class BindPolymerDirective {
@Output("valueChange") change: EventEmitter<any> = new EventEmitter();
@HostListener("value-changed", ["$event.target.value"]) onInputChange(value) {
if (value) {
this.change.emit(value);
}
}
}
<polymer-input [(value)]="user" bindPolymer></polymer-input>
在这种情况下,需要双向绑定的属性是值,所以它就像一个魅力。但在其他情况下,他可能会有所不同。
任何人都可以告诉我如何实现这一目标?或者也许给我另一种解决问题的方法?谢谢
解决方案
在 Javascript 中,对象是引用。
所以简单地做
@Output("valueChange") change: EventEmitter<any> = new EventEmitter();
@Output("valueChangeBis") changeBis = this.change;
应该做的伎俩
推荐阅读
- node.js - 按 ID 删除 MongoDB 子文档
- nuxt.js - 如何使用 vue-i18n 更改属性 lang html
- c - 为什么vmalloc返回的地址不能翻译成物理地址
- apache-spark - 如何刷新非流数据框的内容?
- azure - Azure 函数时间规范
- compilation - 为 Synology 问题编译
- wordpress - 可以在管理仪表板上看到特色图像元标题,但没有添加图像的选项
- flutter - 如何在flutter中选择基于下拉项添加文本字段值
- angular - 箭头运算符 VS 在函数中传递参数:有什么区别?
- flutter - 在处理上一行的结果之前正在执行代码?