当前位置: 首页 > 知识库问答 >
问题:

我在Angular HTML模板中做错了什么?[副本]

太叔小云
2023-03-14
 <div class="col-6">
        <div *ngIf="lessons">
            <div *ngIf="(lessons|async).length > 0">
                <h2>les 3 derniere lessons </h2>
                <hr>
                <ul class="list-group" style="user-select: auto;">
                    <li *ngFor=" let lesson in (lessons | async) | slice:0:3; let i=index "
                        class="list-group-item d-flex justify-content-between align-items-center"
                        style="user-select: auto;">
                        <a [routerLink]="['/lesson', lesson.id, 'view' ]">
                            <span class="badge badge-primary badge-pill" style="user-select: auto;">{{i}}</span>
                            {{lesson.detail}}
                        </a>

                    </li>
                </ul>
            </div>

        </div>
        <div *ngIf="versements">
            <div *ngIf="(versements|async).length > 0">
                <h2>les 3 derniere versements </h2>
                <hr>
                <ul class="list-group" style="user-select: auto;">
                    <li *ngFor=" let versement in (versements | async ) | slice:0:3; let i=index "
                        class="list-group-item d-flex justify-content-between align-items-center"
                        style="user-select: auto;">
                        <a [routerLink]="['/lesson', lesson.id, 'view' ]">
                            <span class="badge badge-primary badge-pill" style="user-select: auto;">{{i}}</span>
                            {{versement.montant?}} : {{versement.date | date :'short'}}
                        </a>

                    </li>
                </ul>
            </div>
        </div>

    </div>
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { IBoxer } from 'app/shared/model/boxer.model';
import { JhiDataUtils, JhiAlertService } from 'ng-jhipster';
import { Observable, of } from 'rxjs';
import { MAN_PICTURE_PATH } from 'app/shared/constants/input.constants';
import { IVersement } from 'app/shared/model/versement.model';
import { VersementService } from '../versement/versement.service';
import { LessonService } from '../lesson/lesson.service';
import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { ILesson } from 'app/shared/model/lesson.model';

@Component({
  selector: 'jhi-boxer-detail',
  templateUrl: './boxer-detail.component.html'
})
export class BoxerDetailComponent implements OnInit {
  boxer: IBoxer;
  versements: Observable<IVersement[]>;
  lessons : Observable<ILesson[]>;
  manPicturePath: any;

  constructor(
    protected jhiAlertService: JhiAlertService,
    protected activatedRoute: ActivatedRoute,
    protected dataUtils: JhiDataUtils,
    protected versementService: VersementService,
    protected lessonService: LessonService
  ) {

  }

  ngOnInit() {
    this.manPicturePath = MAN_PICTURE_PATH;

    this.activatedRoute.data.subscribe(({ boxer }) => {
      this.boxer = boxer;
    });


    this.versementService
      .query({ boxerID: this.boxer.id }, this.versementService.BY_BOXER_ID)
      .subscribe(
        (res: HttpResponse<IVersement[]>) => this.fetchVersementsDatas(res.body),
        (err: HttpErrorResponse) => this.JhiAlertError(err)
      );


    this.lessonService
        .query( {boxerID: this.boxer.id},this.lessonService.BY_BOXER_ID)
        .subscribe(
          (res:HttpResponse<ILesson[]>) => this.fetchLessonsDatas(res.body),
          (err:HttpErrorResponse) => this.JhiAlertError(err)
        );

  }

  fetchLessonsDatas(lessons){
    this.lessons = of(lessons);
  }

  fetchVersementsDatas(versements?: IVersement[]) {
    this.versements = of(versements);
  }

  JhiAlertError(errorMessage: any) {
    this.jhiAlertService.error(errorMessage, null, null);

  }

  byteSize(field: any) {
    return this.dataUtils.byteSize(field);
  }

  openFile(contentType: any, field: any) {
    return this.dataUtils.openFile(contentType, field);
  }

  previousState() {
    window.history.back();
  }
}
core.js?f18e:6014 ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'ngForIn' since it isn't a known property of 'li'. (" > 0"> <h2>les 3 derniere lessons </h2> <hr> <ul class="list-group" style="user-select: auto;"> <li [ERROR ->]*ngFor=" let lesson in (lessons | async) | slice:0:3; let i=index " class="list-group-item d-flex jus"): ng:///BoxingBoxerModule/BoxerDetailComponent.html@0:1790
Property binding ngForIn not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("ngth > 0"> <h2>les 3 derniere lessons </h2> <hr> <ul class="list-group" style="user-select: auto;"> [ERROR ->]<li *ngFor=" let lesson in (lessons | async) | slice:0:3; let i=index " class="list-group-item d-flex"): ng:///BoxingBoxerModule/BoxerDetailComponent.html@0:1786
Parser Error: Unexpected end of expression:  {{versement.montant?}} : {{versement.date | date :'short'}}  at the end of the expression [ {{versement.montant?}} : {{versement.date | date :'short'}} ] in ng:///BoxingBoxerModule/BoxerDetailComponent.html@0:2622 (".id, 'view' ]"> <span class="badge badge-primary badge-pill" style="user-select: auto;">{{i}}</span>[ERROR ->] {{versement.montant?}} : {{versement.date | date :'short'}} </a> </li> </ul> </div> </div> </div> </"): ng:///BoxingBoxerModule/BoxerDetailComponent.html@0:2622
Parser Error: Conditional expression versement.montant? requires all 3 expressions at the end of the expression [ {{versement.montant?}} : {{versement.date | date :'short'}} ] in ng:///BoxingBoxerModule/BoxerDetailComponent.html@0:2622 (".id, 'view' ]"> <span class="badge badge-primary badge-pill" style="user-select: auto;">{{i}}</span>[ERROR ->] {{versement.montant?}} : {{versement.date | date :'short'}} </a> </li> </ul> </div> </div> </div> </"): ng:///BoxingBoxerModule/BoxerDetailComponent.html@0:2622
Can't bind to 'ngForIn' since it isn't a known property of 'li'. ("0"> <h2>les 3 derniere versements </h2> <hr> <ul class="list-group" style="user-select: auto;"> <li [ERROR ->]*ngFor=" let versement in (versements | async ) | slice:0:3; let i=index " class="list-group-item d-f"): ng:///BoxingBoxerModule/BoxerDetailComponent.html@0:2310
Property binding ngForIn not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("h > 0"> <h2>les 3 derniere versements </h2> <hr> <ul class="list-group" style="user-select: auto;"> [ERROR ->]<li *ngFor=" let versement in (versements | async ) | slice:0:3; let i=index " class="list-group-item"): ng:///BoxingBoxerModule/BoxerDetailComponent.html@0:2306

共有1个答案

曹钊
2023-03-14

要进行迭代,需要使用以下语法*ngfor=“let value of values”:

<li *ngFor="let versement of (versements | async ) | slice:0:3; let i=index">
...
</li>

正如Angular docs所说:

为集合中的每个项呈现模板的结构指令。该指令被放置在一个元素上,该元素成为克隆模板的父级。

<li *ngFor="let user of userObservable | async as users; index as i; first as isFirst">
  {{i}}/{{users.length}}. {{user}} <span *ngIf="isFirst">default</span>
</li>
 类似资料:
  • 我不知道我在这里有什么错误,但它不会编译。我得到的错误消息是/"fe"而没有"if"/ /not一个语句//没有"if"/ 我正在按照我作业中的样本所显示的方式来做,我仍然会遇到这个错误。请有人帮我学数学。PI。我完全迷路了。

  • 我正在做一个项目,我的意图是运行一个玉米作业,并发送邮件给我的朋友,祝他们生日,我能够从MySQL DB获取电子邮件,并将其与当前日期进行比较,但当涉及到发送电子邮件时,我得到NullPointerException。 我确信应用程序属性没有问题,我在其他项目中也使用了它们,它们的功能正常 这是我得到以下信息的错误

  • 我正试图将即时消息添加到现有的应用程序中。但是我不确定应该如何配置socket.io模块。我已经尝试了以下方法: 因为打开一个页面时没有记录connected,所以我假设丢失了一些东西。我的错误在哪里?

  • 这不是重复我的问题。我检查了它,我的是如何使用正确的谓词,这是关于removeIf和remove之间的区别。 我是Java程序员的初学者。 昨天,我试着学习了这篇教程https://dzone.com/articles/why-we-need-lambda-expressions 在学习了如何使用Lambda表达式和谓词之后,我制作了自己的代码来练习。 比如,如果(n%3==0n%5==0)和所有

  • 11:15:57创建表如果不存在tblcompany(companyid INT(11)无符号NOT NULL,custfirst VARCHAR(50),custlast VARCHAR(50),company VARCHAR(50),custphone VARCHAR(50), custemail VARCHAR(50),主键(companyid),索引(companyid),约束外键(com

  • 我试图发布一个新的条目到MongoDB,我知道这个问题是我在服务器文件中调用我的路由的地方,但我不知道如何解决这个问题。我需要能够测试在邮递员的API和张贴到数据库。 我得到以下错误: /users/ryan/desktop/leasequery/operations-backend/node_modules/express/lib/router/index.js:458抛出新的TypeError