【问题标题】:"let-" is only supported on ng-template elements"let-" 仅支持 ng-template 元素
【发布时间】:2018-05-31 15:50:14
【问题描述】:

我正在尝试让我的前端应用程序(Angular5.1.x)运行,但由于模板解析错误而停止:

"let-" is only supported on ng-template elements. ("
</thead>
<tbody>
<template ngFor [ngForOf]="rows" [ERROR ->]let-rowz="$implicit" let-    index="index">
<tr *ngIf="!(datePicker.onlyCurrentMonth && rowz[0].sec"):     
ng:///DatepickerModule/DayPickerComponent.html@52:58
    at syntaxError (compiler.js:485)
    at TemplateParser.parse (compiler.js:24633)
    at JitCompiler._parseTemplate (compiler.js:34442)
    at JitCompiler._compileTemplate (compiler.js:34417)
    at compiler.js:34318
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:34318)
    at compiler.js:34188
    at Object.then (compiler.js:474)
    at JitCompiler._compileModuleAndComponents (compiler.js:34187)

我想我需要关注这个主题问题,说明我需要使用 ngx-bootrap@ngx-bootstrap@2.0.0-beta.8,但它不适用于那个或 v.2.0.0-rc .0

https://github.com/valor-software/ngx-bootstrap/issues/3024

...任何帮助表示赞赏

【问题讨论】:

  • 为什么你不能写 ng-template 而不是 template ?
  • 模板已弃用,您应该使用 ng-template。

标签: html angular npm frontend ngx-bootstrap


【解决方案1】:

我从 Angular 4.x.x 升级到 5.x.x 时遇到了这个错误。原代码为:

<template let-item>

</template>

这在 Angular 4 中运行良好,但在 Angular 5 中失败。只需使用 ng-template 即可正常工作(无需安装包,无需清理缓存):

<ng-template let-item>

</ng-template>

【讨论】:

  • 你可能需要让它#let-item
【解决方案2】:

ngx-bootstrap 1.x.x 使用 &lt;template&gt; 已在 angular 5.x.x 中弃用。所以你必须升级到ngx-bootstrap 2.X.X

执行以下升级

npm uninstall --save ngx-bootstrap
npm cache clean -f
npm install --save ngx-bootstrap

【讨论】:

    【解决方案3】:

    v2+ 中没有&lt;template&gt; 标签,请进行全新安装, 并检查您是否拥有 ngx-bootstrap v2+ 检查包锁(如果存在)

    【讨论】:

    • 感谢您的反馈 valorkin,最后我还必须执行 'npm cache clear --force' 才能使其正常工作。
    • 我删除了我的节点模块,删除了npm cache clear --force,但我仍然有这个问题。使用"ngx-bootstrap": "^2.0.2""ngx-date-picker": "0.0.24"
    • 去掉包锁json文件,再做一次
    • 谢谢。我试过了,但我仍然收到此错误。
    • 我新建了一个node项目,导入了ngx-date-picker。版本号为 0.0.24。里面有几个template标签。
    【解决方案4】:

    全部搜索

    1. &lt;template 并替换为&lt;ng-template

    2. &lt;/template&gt; 并替换为&lt;/ng-template&gt;

    【讨论】:

    • 太棒了。谢谢。
    【解决方案5】:

    它也面临同样的问题。通过问题发现我创建的数组是

    <ng-template  ngFor [ngForOf]="names" let-name="$implicit" let-i="index">
      <div><span>{{i+1}}</span> <span> {{name.name}}</span></div>
    </ng-template>
    

    喜欢:-

    names= [{id:1,name:'shashikant'},{id:2,name:'Rakesh'},{id:3,name:'Umesh'}];
    

    然后我替换为:-

    names:Array<any>= [{id:1,name:'shashikant'},{id:2,name:'Rakesh'},{id:3,name:'Umesh'}];
    

    将类型指定为 Array

    【讨论】:

      【解决方案6】:

      您没有在 html 文件中使用 ng-template 标签,但您已将 ngx 模块导入 app.model.ts 那么这将到来。删除您的 app.model 导入语句并构建和检查。

      谢谢。

      【讨论】:

        【解决方案7】:

        我遇到了同样的问题,在我的html文件中用&lt;ng-template&gt;替换&lt;template&gt;标签我解决了这个问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-10-04
          • 2022-01-08
          • 1970-01-01
          • 1970-01-01
          • 2019-02-23
          • 2020-05-22
          • 2018-05-13
          相关资源
          最近更新 更多