簡體   English   中英

如何在角度4中直接在模板綁定中增加變量?

[英]How to increment variable directly in template binding in angular 4?

我有以下對象:

  this.people = [{
        name: 'Douglas  Pace',
        title: 'Parcelivery Nailed The Efficiency',
        content: 'Since I installed this app, its always help me book every tickets I need like flight, concert, ' +
          'movie or hotel. I don\'t need to install different app for different ticket. The payment is also very easy',
        image: '../../assets/img/profile_pics/profile_pic.jpg',
        rate: '4.5',
        classActive: 'testimonials__selected-visible',
        active: true
      },
      {
        name: 'Naseebullah  Ahmadi',
        title: 'Parcelivery Nailed The Efficiency',
        content: 'Since I installed this app, its always help me book every tickets I need like flight, concert, ' +
          'movie or hotel. I don\'t need to install different app for different ticket. The payment is also very easy',
        image: '../../assets/img/profile_pics/profile_pic.jpg',
        rate: '4.5',
        classActive: '',
        active: false
      },
      {
        name: 'Haseebullah Ahmadi',
        title: 'Parcelivery Nailed The Efficiency',
        content: 'Since I installed this app, its always help me book every tickets I need like flight, concert, ' +
          'movie or hotel. I don\'t need to install different app for different ticket. The payment is also very easy',
        image: '../../assets/img/profile_pics/profile_pic.jpg',
        rate: '4.5',
        classActive: '',
        active: false
      }
    ];

我在html中循環這樣:

  <ng-template ngFor let-person="$implicit" let-variable [ngForOf]="people">
          {{variable + 30}}
   <ng-template/>

我的問題是,是否有一種方法可以為模板綁定中的ngfor中的每個元素設置局部變量並將其遞增30? 而不是有方法來增加?

我從方法增加變量的問題是我得到以下錯誤:

錯誤:ExpressionChangedAfterItHasBeenCheckedError:表達式在檢查后已更改

<ng-template ngFor let-person="$implicit" let-variable [ngForOf]="people" let-i="index">
  <p *ngIf="i == 0">{{variable + 30}}</p>
  <p *ngIf="i > 0">{{variable + (30*i)}}</p>
<ng-template/>

通過這樣,您可以獲得從0到總長度的索引。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM