我在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>();