[英]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.