背景:我正在尝试使用PrimeNG的Tree组件,但是在单击以展开节点时遇到以下错误:
UITreeNode.html:6 ERROR TypeError: eventTarget.className.indexOf is not a function
at Tree.onNodeClick (tree.js:270)
at UITreeNode.onNodeClick (tree.js:48)
at Object.eval [as handleEvent] (UITreeNode.html:6)
at handleEvent (core.js:13589)
at callWithDebugContext (core.js:15098)
at Object.debugHandleEvent [as handleEvent] (core.js:14685)
at dispatchEvent (core.js:10004)
at eval (core.js:10629)
at HTMLDivElement.eval (platform-browser.js:2628)
at ZoneDelegate.invokeTask (zone.js:425)
追踪错误,看起来有问题的代码在这里:
Tree.prototype.onNodeClick = function (event, node) {
var eventTarget = event.target;
if (eventTarget.className && eventTarget.className.indexOf('ui-tree-toggler') === 0) {
return;
}
进一步挖掘:我向我的树中添加了一个click事件,以查看事件的外观(尽管这可能是完全错误的,因为这可能与实际错误有所不同),并且发现当您单击某个节点时,将返回以下内容:
SVGAnimatedString {
baseVal: "svg-inline--fa fa-caret-right fa-w-6 ui-tree-toggler fa-fw",
animVal: "svg-inline--fa fa-caret-right fa-w-6 ui-tree-toggler fa-fw"
}
其他可能相关的依赖项和代码:
"@angular/animations": "^5.2.10",
"@angular/cdk": "^5.2.1",
"@angular/common": "^5.2.10",
"@angular/compiler": "^5.2.10",
"@angular/core": "^5.2.10",
"@angular/forms": "^5.2.10",
"@angular/http": "^5.2.10",
"@angular/material": "^5.2.1",
"@angular/platform-browser": "^5.2.10",
"@angular/platform-browser-dynamic": "^5.2.10",
"@angular/router": "^5.2.10",
"primeng": "^5.2.4"
树代码:
<p-tree [value]="files" (click)="log($event)"></p-tree>
文件只是docs中提供的默认文件。
登录方式:
log(event) {
console.log(event.target.className);
}
问题:我似乎无法在stackblitz或plnkr中复制它,因此也许存在一些影响树的叛逆代码?
或者我的PrimeNG / Angular版本已经过时,并且在升级中得到了解决?
感谢您的帮助!