2017-05-09 120 views
0

我尝试使用NgTabset,但出现此错误TypeError:无法读取属性'templateRef'undefined 。当我用模板代替ng-template标签一切正常。我做错了什么? 下面是代码:Angular 2 ng-bootstrap,NgbTabset错误:Uncaught(在承诺中):TypeError:无法读取属性'templateRef'undefined

<ngb-tabset> 
    <ngb-tab> 
    <ng-template ngbTabTitle> 
     Tab1 
    </ng-template> 
    <ng-template ngbTabContent> 
     Here is tab 1 
    </ng-template> 
    </ngb-tab> 
</ngb-tabset> 
+1

听起来像一个依赖性错误。要么你错过了从模块导入,或者你需要更新你的Angular版本。 –

回答

0

这一点很难知道没有Plunkr,但一定要设置templateRef和#

<app-content [templateRef]="nestedComponentRef"></app-content> 
<template #nestedComponentRef> 
    <component> 
    </component> 
</template> 

下面是一个例子:https://embed.plnkr.co/zsG5ROJD1jYVIoXaR9Ga/

0

的评论由David Aguirre提出这是一个依赖性问题,但似乎至少部分归因于ng-bootstrap版本。

我有这个同样的问题,发现我的NG-引导的版本是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/[email protected]/bundles/ng-bootstrap.js'

当我降低了该版本数字为1.0.0-alpha.24我得到了下面的一堆错误消息。

焦仲卿到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/[email protected]: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 

希望当其他人得到这些信息,他们会发现这个线程。

如果警告和错误信息没有那么具有误导性和不明确,这将会有所帮助。

相关问题