Angular 6中不相关的模板解析错误

时间:2019-05-28 12:45:46

标签: html angular typescript

我正在开发一个简单的Angular 6应用程序。在某个时候出现了“模板解析错误”,字面意思是:“ let-”仅在ng-template元素上受支持。我在代码中不使用任何模板或ng-template。有人有主意吗?

Uncaught Error: Template parse errors:
"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@38:37
"let-" is only supported on ng-template elements. ("
  </thead>
  <tbody>
    <template ngFor [ngForOf]="rows" let-rowz="$implicit" [ERROR ->]let-index="index">
      <tr *ngIf="!(datePicker.onlyCurrentMonth && rowz[0].secondary && rowz[6].sec"): ng:///DatepickerModule/DayPickerComponent.html@38:58
    at syntaxError (compiler.js:2547)
    at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:19495)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:25041)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:25028)
    at compiler.js:24971
    at Set.forEach (<anonymous>)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:24971)
    at compiler.js:24881
    at Object.then (compiler.js:2538)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:24880)

2 个答案:

答案 0 :(得分:1)

如果我没记错的话,您使用的是* ngFor,并且您尝试获取索引,如果是这种情况,请尝试以下示例。

<div *ngFor="let element of array; let $index = index">{{$index}}</div>

我认为您正在做的是let-index = index;,我从您上传的错误跟踪中得出了结论。您在let和index之间使用-。

答案 1 :(得分:0)

问题可能是“ ngx-bootstrap”,请尝试将其删除并使用“ ngx-bootstrap”;