Am 21.02.2017 um 08:49 schrieb Yuvraj Chauhan:
I want to migrate one of my big Angular JS 1 project module. But
facing problem with *ngFor. My current module iterates over object
(key, value) pair and Angular 2 is not supporting iteration on
Objects. Do you have any idea how can I handle this situation? Is
there any alternative of *ngFor? I can not change the existing Object
structure to Array. Can you please help me?

Why don't you create a helper function that converts your objects to arrays? Like this:


  obj = {key1: 'value1', key2: 'value2', key3: 'value3'};

  itemArray(obj) {
    return Object.keys(obj).map(key => [key, obj[key]])
  }

When targeting ES6, you could also use a generator.

Then you can iterate over your object like this:

    <li *ngFor="let item of itemArray(obj)">
      Key: {{item[0]}}, Value: {{item[1]}}
    </li>

You can also create a custom directive that extends ngFor.

-- Chris

--
You received this message because you are subscribed to the Google Groups "Angular 
and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to