My challenge is to access a global variable public right: any = 30;
I need to uniquely call this variable from each element and increment it by 30 in an ngFor loop iterating over the People
object:
interface Person {
name: String,
title: String,
content: String,
image: String,
rate: String,
classActive: String,
active: Boolean
}
@Component({
selector: 'app-testimonials',
templateUrl: './testimonials.component.html',
styleUrls: ['./testimonials.component.scss']
})
export class TestimonialsComponent {
people: Person[] = [{
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
}
];
public right: any = 30;
constructor() {}
stackItem(a) {
console.log(a);
}
}
<div *ngFor="let person of people; let last = last"
class="testimonials__card-container"
#__person
[ngClass]="{'testimonials__card-container--not-visible': !person.active}"
[style.right]="stackItem(__person.right)">
</div>
In Angular 2, we used to call global variables as an instance for each element in ngFor, but that changed in angular 4. Are there any alternative approaches?