我已经使用 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/