问题描述
我有一个项目,我最近从 Angular 8 迁移到了 Angular 9.该项目使用 primeng version : 4.3.0
.现在 p-radiobutton
标签在整个项目中被广泛使用来显示单选按钮,但它不能正常工作.p-radiobutton
标签给出了运行时错误:无法获取未定义或空引用的属性nativeElement"
,因此,UI 会失真.整个错误堆栈跟踪如下所示:
I have a project which I have recently migrated to Angular 9 from Angular 8 . The project uses primeng version : 4.3.0
. Now the p-radiobutton
tag is widely used through out the project to display radio buttons and it is not working properly . The p-radiobutton
tag gives the runtime error : Unable to get property 'nativeElement' of undefined or null reference
due to which , the UI gets distorted . The entire error stack trace is depicted down below :
TypeError: Unable to get property 'nativeElement' of undefined or null reference
at RadioButton.prototype.writeValue (http://localhost:4200/vendor.js:115296:9)
at setUpControl (http://localhost:4200/vendor.js:79928:5)
at NgModel.prototype._setUpStandalone (http://localhost:4200/vendor.js:82718:9)
at NgModel.prototype._setUpControl (http://localhost:4200/vendor.js:82706:32)
at NgModel.prototype.ngOnChanges (http://localhost:4200/vendor.js:82630:13)
at checkAndUpdateDirectiveInline (http://localhost:4200/vendor.js:67503:9)
at checkAndUpdateNodeInline (http://localhost:4200/vendor.js:76327:13)
at checkAndUpdateNode (http://localhost:4200/vendor.js:76289:9)
at prodCheckAndUpdateNode (http://localhost:4200/vendor.js:76833:5)
at Anonymous function (Function code:194:5)
由于引发错误而导致的 html 中的代码行是这样的:
The line of code in the html due to which the error is being thrown is this :
<td class="alignHere">
<p-radioButton name="myStuff" value="CAT" [(ngModel)]="StuffChosen"></p-radioButton>
</td>
当我注释掉上面这段代码时,错误不再出现,但我需要使用单选按钮功能.
When I comment out the above piece of code, the error does no come up anymore , but I need to use the radio button functionality .
有没有人知道这个错误是什么以及这个问题的潜在解决方案是什么?任何帮助深表感谢.
Does anybody have any idea about what this error is and what can be a potential solution to this problem ? Any help is deeply appreciated .
推荐答案
primeng 将版本与 angular version 放在一起,这意味着 primeng 10 用于 angular 10,primeng 11 用于 angular 11,这适用于旧版本.
primeng line the versions with angular version , this mean primeng 10 is used for angular 10 , primeng 11 for angular 11 and this apply to old version.
您收到错误消息,因为在primeng 4 中某些角度API 已更改或删除.
you get an error because in primeng 4 some angular api has changed or removed.
要解决您的问题,只需选择您的 Angular 应用程序版本的 Primeng 版本库
to solve your problem just chose the primeng version base of your angular app version
这篇关于为什么使用primeng p-radiobutton会导致Angular 9中的原生元素错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!