简体   繁体   English

避免在priming列表框组件中的“ Banana In A Box”中

[英]Avoid Banana In A Box in primeng listbox component

I'm using primeng listbox component, and want to avoid banana in a box 2 way data binding, as it's not recommended. 我正在使用primeng listbox组件,并希望避免banana in a box 2方式数据绑定banana in a box ,因为不建议这样做。 html side gives this: html边给出了这个:

<p-listbox [options]="cities1" [(ngModel)]="selectedCity"></p-listbox>

and TS side only the declaration of selectedCity for now: TS仅支持selectedCity的声明:

selectedCity: City;

and City is an interface: City是一个接口:

export Interface City {
   id: string;
   name: string;
   continent: string;
}

And by avoiding BIAB => have an input to my listbox component, so I can pass the selected city as a parameter, and an output to emit when selection done. 并且通过避免BIAB =>对列表框组件具有输入,因此我可以将所选城市作为参数传递,并在选择完成后发出输出。

In AngularJS, too many two-way bindings can hinder performance as it can create too many watchers. 在AngularJS中,太多的双向绑定会阻碍性能,因为它会创建太多的观察者。

However, in Angular, two-way bindings is simply a syntactic sugar of applying both property binding and event binding. 但是,在Angular中,双向绑定只是同时应用属性绑定和事件绑定的语法糖。

So, you don't really have to avoid two-way binding in Angular. 因此,您实际上不必避免在Angular中进行双向绑定。

See https://angular.io/guide/template-syntax#two-way-binding--- for more info. 有关更多信息,请参见https://angular.io/guide/template-syntax#two-way-binding---

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM