I am getting below the error in my code.
let getVal: string
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'AppComponent'.
No index signature with a parameter of type 'string' was found on type 'AppComponent'.ts(7053)
So, How to resolve like this type declaration issue in typescript.If anyone knows please help to resolve.
app.component.html:
<button *ngFor="let season of seasons" (click)="show(season)">
{{ season }}
</button>
<div *ngIf="group1">Group 1 content</div>
<div *ngIf="group2">Group 2 content</div>
<div *ngIf="group3">Group 3 content</div>
app.component.ts:
seasons = ['Group 1', 'Group 2', 'Group 3'];
group1: boolean = false;
group2: boolean = false;
group3: boolean = false;
show(val: string) {
for (var i = 0; i < this.seasons.length; i++) {
if (this.seasons[i] === val) {
let getVal = val.toLowerCase().replace(/\s/g, '');
this[getVal] = true; // getting error here
} else {
let getVal = this.seasons[i].toLowerCase().replace(/\s/g, '');
this[getVal] = false; // getting error here
}
}
}