Answer the question
In order to leave comments, you need to log in
How to properly write logic in *ngFor?
I have an object in which each property is an object.
objectKeys = Object.keys;
tableColumnsConfig: any = {
id: {
name: 'ID',
value: true
},
title: {
name: 'Застройщик',
value: true
},
phone: {
name: 'Телефон',
value: true
},
website: {
name: 'URL',
value: false
},
avitoId: {
name: 'Avito ID',
value: true
}
}
<div *ngFor="let key of objectKeys(tableColumnsConfig)">
{{tableColumnsConfig[key].name}}
</div>
Answer the question
In order to leave comments, you need to log in
<div *ngFor="let column of tableColumnsConfig | toIterable | trueOnlyBy : 'value'">
{{column.name}}
</div>
@Pipe({
name: 'toIterable'
})
export class ToIterablePipe implements PipeTransform {
transform(dict: Object) {
return Object.keys(dict || {}).map(key => dict[key]);
}
}
@Pipe({
name: 'trueOnlyBy'
})
export class TrueOnlyByPipe implements PipeTransform {
transform(arr: any[], propName: string): object {
return arr.filter(item => !!item[propName]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question