![](/img/trans.png)
[英]EXCEPTION: Error in ./NgbTabset class NgbTabset - inline template:12:20 caused by: Cannot read property 'templateRef' of undefined
[英]Angular 2 ng-bootstrap,NgbTabset Error:Uncaught (in promise): TypeError: Cannot read property 'templateRef' of undefined
我尝试使用NgTabset,但出现此错误TypeError:无法读取未定义的属性'templateRef'。当我用template标签替换ng-template时 ,一切正常。我在做什么错? 这是代码:
<ngb-tabset>
<ngb-tab>
<ng-template ngbTabTitle>
Tab1
</ng-template>
<ng-template ngbTabContent>
Here is tab 1
</ng-template>
</ngb-tab>
</ngb-tabset>
如果没有Plunkr,很难知道,但是请务必设置templateRef和#
<app-content [templateRef]="nestedComponentRef"></app-content>
<template #nestedComponentRef>
<component>
</component>
</template>
这是一个示例: https : //embed.plnkr.co/zsG5ROJD1jYVIoXaR9Ga/
David Aguirre的评论暗示这是一个依赖性问题,但这似乎至少部分归因于ng-bootstrap版本。
我遇到了同样的问题,并注意到我的ng-bootstrap版本是1.0.0-alpha.24,但在示例中位于https://ng-bootstrap.github.io/app/components/tabset/demos/basic/ plnkr.html config.js中的行是'@ng-bootstrap/ng-bootstrap': 'npm:@ng-bootstrap/ng-bootstrap@1.0.0-alpha.28/bundles/ng-bootstrap.js'
当我将该版本号降低到1.0.0-alpha.24时,出现了以下错误消息。
在Web上的代码版本中进行的更改最大达到1.0.0-alpha.28,但是在VCCode开发环境中的代码中,我发现只需将<template>
更改为<ng-template>
,
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.24",
在package.json中
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.28",
还不足以解决问题,但是创建一个新的CLI实例可以解决此问题,因此必须存在我没有找到的其他依赖项。
https://ng-bootstrap.github.io/app/components/tabset/demos/basic/plnkr.html上带有1.0.0-alpha.24的警告是:
Template parse warnings:
The <template> element is deprecated. Use <ng-template> instead ("[WARNING ->]<template ngFor [ngForOf]="parts" let-part let-isOdd="odd"><span *ngIf="isOdd" class="{{highlightClas"): ng:///NgbTypeaheadModule/NgbHighlight.html@0:0
这是一种误导,因为代码使用了<ng-template>
,而不是警告中要求的<template>
元素。
错误消息的第一行是:
ERROR TypeError: Cannot read property 'templateRef' of undefined
ERROR CONTEXT DebugContext_ {view: Object, nodeIndex: 3, nodeDef: Object, elDef: Object, elView: Object}
Unhandled Promise rejection: Cannot read property 'templateRef' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'templateRef' of undefined
Error: Uncaught (in promise): TypeError: Cannot read property 'templateRef' of undefined
希望当其他人收到这些消息时,他们将找到此线程。
如果警告和错误消息没有那么令人误解和不清楚,这将很有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.