删除ngFor中的前4个字符

时间:2018-10-23 05:35:42

标签: javascript angular angular5 ngfor

我在ngFor下面有一个要删除的c.FilmCode的前四个字符

 <li class="">
    <a [(ngModel)]="selectedmovies" ngDefaultControl name="" class="form-control" (click)="togglemovies()" id="cbocmovies" [ngModelOptions]="{standalone: true}">{{selectedmoviestext}}</a>
    <div [ngClass]="{toggleMovie:IsToggleMovie==true}" *ngIf="movies.length > 0">
        <ul class="clearfix">
            <li *ngFor="let c of movies" [value]="c.FilmCode" (click)="OnMoviesChange(c.FilmTitle,c.FilmCode)">{{c.FilmTitle}}</li>
        </ul>
    </div>
</li>

下面是ts代码

showmoviecombo(CinemaId) {
  this.common.createAPIService('api/cinemas/GetListByCinemaId?CinemaId=' + CinemaId, '').subscribe((result: any) => {
        this.movies = result;
        //this.movieids = this.movies.FilmCode;
        console.log(this.movieids);
  });
}

有什么办法吗?

2 个答案:

答案 0 :(得分:1)

您还可以使用 Slice 删除前四个字符

<li class="">
<a [(ngModel)]="selectedmovies" ngDefaultControl name="" class="form-control" (click)="togglemovies()" id="cbocmovies" [ngModelOptions]="{standalone: true}">{{selectedmoviestext}}</a>
<div [ngClass]="{toggleMovie:IsToggleMovie==true}" *ngIf="movies.length > 0">
    <ul class="clearfix">
        <li *ngFor="let c of movies" [value]="c.FilmCode" (click)="OnMoviesChange(c.FilmTitle,c.FilmCode)">{{c.FilmTitle.slice(4)}}</li>
    </ul>
</div>

答案 1 :(得分:0)

您可以在字符串值方法上使用substring

 <li class="">
    <a [(ngModel)]="selectedmovies" ngDefaultControl name="" class="form-control" (click)="togglemovies()" id="cbocmovies" [ngModelOptions]="{standalone: true}">{{selectedmoviestext}}</a>
    <div [ngClass]="{toggleMovie:IsToggleMovie==true}" *ngIf="movies.length > 0">
        <ul class="clearfix">
            <li *ngFor="let c of movies" [value]="c.FilmCode" (click)="OnMoviesChange(c.FilmTitle,c.FilmCode)">{{c.FilmTitle?.substring(4)}}</li>
        </ul>
    </div>
</li>