Angular 2 ng-bootstrap,NgbTabset错误:未捕获(承诺):TypeError:无法读取未定义的属性"templateRef" [英] Angular 2 ng-bootstrap,NgbTabset Error:Uncaught (in promise): TypeError: Cannot read property 'templateRef' of undefined

查看:86
本文介绍了Angular 2 ng-bootstrap,NgbTabset错误:未捕获(承诺):TypeError:无法读取未定义的属性"templateRef"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用NgTabset,但出现此错误 TypeError:无法读取未定义的属性'templateRef'.当我将 ng-template 替换为 template 标签,一切正常.我在做什么错? 这是代码:

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? 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>

推荐答案

David Aguirre的评论暗示这是一个依赖关系问题,但这似乎至少部分归因于ng-bootstrap版本.

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.

我遇到了同样的问题,并注意到我的ng-bootstrap版本是1.0.0-alpha.24,但是在

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'

当我将该版本号降低到1.0.0-alpha.24时,出现了以下错误消息.

When I lowered that version number to 1.0.0-alpha.24 I got the bunch of error messages below.

在Web上的代码版本中最多进行了1.0.0-alpha.28的更改,但是在VCCode开发环境中的代码中,我发现只需将<template>更改为<ng-template>

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

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

在package.json中

in package.json to

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

不足以解决问题,但是创建一个新的CLI实例可以解决此问题,因此必须存在我找不到的其他一些依赖项.

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.

https://ng- bootstrap.github.io/app/components/tabset/demos/basic/plnkr.html 与1.0.0-alpha.24为:

The warning at https://ng-bootstrap.github.io/app/components/tabset/demos/basic/plnkr.html with 1.0.0-alpha.24 was:

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>元素.

This was misleading since the code uses the <ng-template>, not the <template> element as claimed in the warnings.

错误消息的第一行是:

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.

这篇关于Angular 2 ng-bootstrap,NgbTabset错误:未捕获(承诺):TypeError:无法读取未定义的属性"templateRef"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆