为什么使用 primeng p-radiobutton 会导致 Angular 9 中出现原生元素错误?

2024-01-31

我有一个项目最近从 Angular 8 迁移到 Angular 9 。该项目使用primeng version : 4.3.0。现在p-radiobutton标签在整个项目中广泛用于显示单选按钮,但它无法正常工作。这p-radiobutton标签给出运行时错误:Unable to get property 'nativeElement' of undefined or null reference因此,用户界面会扭曲。整个错误堆栈跟踪如下所示:

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 中引发错误的代码行是这样的:

<td class="alignHere">
    <p-radioButton name="myStuff" value="CAT" [(ngModel)]="StuffChosen"></p-radioButton>
</td> 

当我注释掉上面的代码时,错误不再出现,但我需要使用单选按钮功能。

有谁知道这个错误是什么以及这个问题的潜在解决方案是什么?非常感谢任何帮助。


primeng 将版本与 Angular 版本对齐,这意味着 primeng 10 用于 Angular 10,primeng 11 用于 Angular 11,这适用于旧版本。

你会得到一个错误,因为在 primeng 4 中,一些 Angular api 已更改或删除。

为了解决您的问题,只需选择您的角度应用程序版本的 primeng 版本基础

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么使用 primeng p-radiobutton 会导致 Angular 9 中出现原生元素错误? 的相关文章

随机推荐