I dug through and found out that I can use the following to use * ngFor over an object:
<div *ngFor="#obj of objs | ObjNgFor">...</div>
where is ObjNgFor pipe:
@Pipe({ name: 'ObjNgFor', pure: false }) export class ObjNgFor implements PipeTransform { transform(value: any, args: any[] = null): any { return Object.keys(value).map(key => value[key]); } }
However, when I have an object like this:
{ "propertyA":{ "description":"this is the propertyA", "default":"sth" }, "propertyB":{ "description":"this is the propertyB", "default":"sth" } }
I'm not quite sure how I can extract 'propertyA' and 'propertyB' so that it is accessible from the * ngFor directive. Any ideas?
UPDATE
What I want to do is submit the following HTML:
<div *ngFor="#obj of objs | ObjNgFor" class="parameters-container"> <div class="parameter-desc"> {{SOMETHING}}:{{obj.description}} </div> </div>
Where something will be equal to propertyA and propertyB (this is how the object is structured). Thus, this will result in:
propertyA:this is the propertyA propertyB:this is the propertyB
object angular typescript ngfor
uksz May 05 '16 at 8:42 a.m. 2016-05-05 08:42
source share