简体   繁体   English

Angular 2 ng-bootstrap,NgbTabset错误:未捕获(承诺):TypeError:无法读取未定义的属性“ templateRef”

[英]Angular 2 ng-bootstrap,NgbTabset Error:Uncaught (in promise): TypeError: Cannot read property 'templateRef' of undefined

I try to use NgTabset but i get this error TypeError: Cannot read property 'templateRef' of undefined .When i replace the ng-template with the template tag everything works fine .What am i doing wrong? 我尝试使用NgTabset,但出现此错误TypeError:无法读取未定义的属性'templateRef'。当我用template标签替换ng-template时 ,一切正常。我在做什么错? Here is the code: 这是代码:

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

It's a little hard to know without a Plunkr, but be sure to set templateRef and the # 如果没有Plunkr,很难知道,但是请务必设置templateRef和#

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

Here's an example: https://embed.plnkr.co/zsG5ROJD1jYVIoXaR9Ga/ 这是一个示例: https : //embed.plnkr.co/zsG5ROJD1jYVIoXaR9Ga/

The comment by David Aguirre suggested this is a dependency issue, but it seems to due at least in part to the ng-bootstrap version. David Aguirre的评论暗示这是一个依赖性问题,但这似乎至少部分归因于ng-bootstrap版本。

I had this same problem and noticed that my version of ng-bootstrap was 1.0.0-alpha.24, but in the example at https://ng-bootstrap.github.io/app/components/tabset/demos/basic/plnkr.html the line in config.js was '@ng-bootstrap/ng-bootstrap': 'npm:@ng-bootstrap/ng-bootstrap@1.0.0-alpha.28/bundles/ng-bootstrap.js' 我遇到了同样的问题,并注意到我的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'

When I lowered that version number to 1.0.0-alpha.24 I got the bunch of error messages below. 当我将该版本号降低到1.0.0-alpha.24时,出现了以下错误消息。

Making the change up to 1.0.0-alpha.28 worked in the version of our code on the Web, but in the code in the VCCode development environment I found that just changing <template> to <ng-template> and 在Web上的代码版本中进行的更改最大达到1.0.0-alpha.28,但是在VCCode开发环境中的代码中,我发现只需将<template>更改为<ng-template>

"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.24",

in package.json to 在package.json中

"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.28",

was not enough to fix the problem, but creating a new CLI instance fixed the problem, so there must be some other dependency that I didn't find. 还不足以解决问题,但是创建一个新的CLI实例可以解决此问题,因此必须存在我没有找到的其他依赖项。

The warning at https://ng-bootstrap.github.io/app/components/tabset/demos/basic/plnkr.html with 1.0.0-alpha.24 was: 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

This was misleading since the code uses the <ng-template> , not the <template> element as claimed in the warnings. 这是一种误导,因为代码使用了<ng-template> ,而不是警告中要求的<template>元素。

The first lines of the error messages were: 错误消息的第一行是:

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

Hopefully when other people get these messages they will find this thread. 希望当其他人收到这些消息时,他们将找到此线程。

It would be helpful if the warning and error message were not so misleading and unclear. 如果警告和错误消息没有那么令人误解和不清楚,这将很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 例外:./ NgbTabset类NgbTabset中的错误-内联模板:12:20由以下原因引起:无法读取未定义的属性&#39;templateRef&#39; - EXCEPTION: Error in ./NgbTabset class NgbTabset - inline template:12:20 caused by: Cannot read property 'templateRef' of undefined Angular 2.2和ng-bootstrap无法读取未定义的属性“可观察” - Angular 2.2 and ng-bootstrap Cannot read property 'Observable' of undefined 错误 Angular 未捕获类型错误:无法在引导时读取未定义的属性“绑定” - Error Angular Uncaught TypeError: Cannot read property 'bind' of undefined at bootstrap Angular 2-未捕获(承诺):TypeError:无法读取未定义的属性“ title” - Angular 2 - Uncaught (in promise): TypeError: Cannot read property 'title' of undefined 未捕获(承诺):类型错误:无法读取 angular2+ 中未定义的属性“get” - Uncaught (in promise): TypeError: Cannot read property 'get' of undefined in angular2+ 未捕获(承诺):类型错误:无法读取角度 10 中未定义的属性“ɵcmp” - Uncaught (in promise): TypeError: Cannot read property 'ɵcmp' of undefined in angular 10 错误错误:未捕获(承诺):类型错误:无法读取未定义的属性“key” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'key' of undefined 错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ nativeElement” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'nativeElement' of undefined Angular 2 Uncaught(承诺):TypeError:无法读取未定义的属性'isActivated' - Angular 2 Uncaught (in promise): TypeError: Cannot read property 'isActivated' of undefined 错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ map” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'map' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM