angular – 为自定义属性实现双向数据绑定

前端之家收集整理的这篇文章主要介绍了angular – 为自定义属性实现双向数据绑定前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在primeng组件中看到像这样的某些属性使用类似ngModel(双向数据绑定)样式的东西

[(selection)]="selectedItem";

它看起来像

@Input() selection;
@Output() selection:EventEmitter<any> = new EventEmitter<any>();

我如何能够实现这样的东西,并且可以做更多的单一属性

<component-a  [(selection)]="selectedItem"  [(data)]="selectedData"></component-a>

解决方法

Angular docs

<app-sizer 
  [(size)]="fontSizePx">
</app-sizer>

The two-way binding Syntax is really just syntactic sugar for a
property binding and an event binding. Angular desugars the
binding into this:

<app-sizer
  [size]="fontSizePx"
  (sizeChange)="fontSizePx=$event">
</app-sizer>

要为属性选择创建双向绑定,请使用:

@Input() selection;
@Output() selectionChange:EventEmitter<any> = new EventEmitter<any>();

猜你在找的Angularjs相关文章