加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:55:22 所属栏目:安全 来源:网络整理
导读:我在primeng组件中看到像这样的某些属性使用类似ngModel(双向数据绑定)样式的东西 [(selection)]="selectedItem"; 它看起来像 @Input() selection;@Output() selection:EventEmitterany = new EventEmitterany(); 我如何能够实现这样的东西,并且可以做更多的
我在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>();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读