为什么使用primeng p-radiobutton会导致Angular 9中的本机Element错误? [英] Why does usage of primeng p-radiobutton cause native Element error in Angular 9?

查看:113
本文介绍了为什么使用primeng p-radiobutton会导致Angular 9中的本机Element错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,最近从Angular 8迁移到了Angular 9.该项目使用 primeng版本: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用尖角版本标记版本,这意味着尖角10用于角度10,尖角11用于角度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.

要解决您的问题,只需选择角度应用程序版本的primeng版本库

to solve your problem just chose the primeng version base of your angular app version

这篇关于为什么使用primeng p-radiobutton会导致Angular 9中的本机Element错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆