angular - pKeyFIlter : NG8007: The property and event halves of the two-way binding 'ngModel' are not bound to the same target

标签 angular primeng

我已经使用 Primeng 控件将我的 Angular 11 项目更新为 Angular 12。完成后,primeng pKeyFilter 在任何使用它的地方都会抛出错误。从头开始创建一个新的 Angular 12 项目没有这个问题。升级后其他一切似乎都可以正常工作。有什么想法吗?
这是组件

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-key',
  templateUrl: './key.component.html',
  styleUrls: ['./key.component.scss']
})
export class KeyComponent implements OnInit {
  public myvalue: string = '';

  constructor() { }

  ngOnInit(): void {
  }

}
这是 HTML
<input type="text" pInputText [(ngModel)]="myvalue" pKeyFilter="int"/>

<p>
  <span>{{myvalue}}</span>
</p>
这是完整的错误

Error: src/app/modules/nourishment/pages/test/key/key.component.html:1:23 - error NG8007: The property and event halves of the two-way binding 'ngModel' are not bound to the same target. Find more at https://angular.io/guide/two-way-binding#how-two-way-binding-works

1 <input type="text" [(ngModel)]="myvalue" pKeyFilter="int"/> ~~~~~~~

node_modules/@angular/forms/forms.d.ts:3297:22 3297 export declare class NgModel extends NgControl implements OnChanges, OnDestroy { ~~~~~~~ The property half of the binding is to the 'NgModel' component.

node_modules/primeng/keyfilter/keyfilter.d.ts:6:22 6 export declare class KeyFilter implements Validator { ~~~~~~~~~ The event half of the binding is to the 'KeyFilter' component.

src/app/modules/nourishment/pages/test/key/key.component.ts:5:16 5 templateUrl: './key.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component KeyComponent.


我了解错误背后的基础知识,但我无法弄清楚是什么触发了它。我在父模块中导入了质数 InputModule 和 KeyFilterModule 以及 FormsModule 。同样,这一切在升级之前都有效。 https://www.primefaces.org/primeng/showcase/#/keyfilter

最佳答案

我只是先更改了 [(ngModel)] 的顺序,最后更改了 [pKeyFilter] 的顺序
来自 :

<input type="text"  pInputText [pKeyFilter]="'money'" [(ngModel)]="tare" >
:
<input type="text"  pInputText  [(ngModel)]="tare" [pKeyFilter]="'money'" >
它的工作良好

关于angular - pKeyFIlter : NG8007: The property and event halves of the two-way binding 'ngModel' are not bound to the same target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68764954/

相关文章:

angular - 在发送其他请求之前,不会重复/执行 http GET

javascript - 我应该手动向 Google Analytics 发送 JS 异常吗?

css - PrimeNG 日历 - 覆盖默认样式

angular - stepMinute 在 PrimeNG 的日历中不起作用

javascript - Angular5/PrimeNG - p-listbox - onDblClick - 事件问题

c# - Angular 在更改区域性后使用逗号而不是点作为小数点分隔符

angular - 如何在 Apache-tomcat 服务器中运行 Angular 4.6 应用程序?

javascript - 手动关闭 p-calendar 日期选择器

PRIME ng 确认服务的 Angular 单元测试

typescript - @Input() 返回 [object Object] Typescript Angular2