I am new to TypeScript and working on an Angular project.
I am making an API call and making few operations on the data received:
public data_Config: IConfig[] = [];
this.getService.Data(input).subscribe(
data => {
this.data_Config = data;
this.data_Config.forEach(itm => {
if(itm.aFl == 'Y'){
itm.Levels.push('A')
}
if(itm.bFl == 'Y'){
itm.Levels.push('B')
}
if(itm.cFl == 'Y'){
itm.Levels.push('C')
}
});
this.dataSource_prgmConfiguration = new MatTableDataSource(this.data_prgmConfiguration);
this.dataSource_prgmConfiguration.paginator = this.paginatorPrgmConfiguration;
this.dataSource_prgmConfiguration.sort = this.sortPrgmConfiguration;
});
IConfig has several properties including 10-12 flag properties likeaFl,bFl,cFl. Among the Flag properties which ever are true I want to add them to an array. I have done it in a simple way using if condition, but with 11-12 flags as many if conditions will be required, is there any better way to implement this?
Adding IConfig
export interface IConfig {
TypeNm: string;
aFl: string;
bFl: string;
cFl: string;
dFl: string;
eFl: string;
fFl: string;
gFl: string;
hFl: string;
PlaceHolder: string;
Association: string;
ActiveFl: string;
Actions: string;
AssociatedProgramsStr?: string;
Levels?: string[];
}
IConfigdefinitionIConfigdefinition