So I am not sure whether the question is stupid or not, however I feel like my current solution isn't the best.
So I am basically working on a pricing table on the backend. There a 3 different status (plural?). First one is display, second one is edit, third one is 'hidden' and there is a + button to ad a new one.
So now for each column I have prepared three scenarios which I than show/hide with ngIf. I started now working on the actual functions. Like changing when I click buttons and so on.
import { Component, ViewEncapsulation } from '@angular/core';
declare var jQuery: any;
@Component({
selector: '[packages]',
templateUrl: './packages.template.html',
encapsulation: ViewEncapsulation.None,
styleUrls: ['./packages.style.scss']
})
export class PackagesComponent {
tier1Status = '';
tier2Status = '';
tier3Status = '';
currentTiers = 1;
ngOnInit() {
this.checkTiers();
}
checkTiers() {
if (this.currentTiers === 1) {
this.tier1Status = 'show';
this.tier2Status = 'notSetUp';
this.tier3Status = 'hide';
}
else if (this.currentTiers === 2) {
this.tier1Status = 'show';
this.tier2Status = 'show';
this.tier3Status = 'notSetUp';
}
else if (this.currentTiers === 3) {
this.tier1Status = 'show';
this.tier2Status = 'show';
this.tier3Status = 'show';
}
}
addTier(tierNumber: number) {
if (tierNumber === 1) {
this.tier1Status = 'edit';
} else if (tierNumber === 2) {
this.tier2Status = 'edit';
} else if (tierNumber === 3) {
this.tier3Status = 'edit';
}
}
}
So as already mentioned, I am not sure whether this is the best solution. It seems a little complicated. I was wondering whether there is something to make a variabel variabel. Sounds stupid, but basically to have a variabel like tierStatus[x] and when I click a button I always pass which tier is meant. Sorry I am quiet new to angular2 and typescript/javascript in general. Maybe be something like this
clickEdit (tierNumber: number) {
tierStatus[tierNumber] = 'edit';
}
Thanks a lot. Cheers