Alternative of *ngFor

650 views
Skip to first unread message

Yuvraj Chauhan

unread,
Feb 21, 2017, 2:49:16 AM2/21/17
to Angular and AngularJS discussion
Hello All,
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?

Thanks,
Yuvraj Chauhan. 

Christoph Zwerschke

unread,
Feb 21, 2017, 4:00:45 AM2/21/17
to ang...@googlegroups.com
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

Yuvraj Chauhan

unread,
Feb 21, 2017, 8:49:33 AM2/21/17
to Angular and AngularJS discussion
Thanks for your reply Christoph Zwerschke. But I have to loop over that object also in next step once I converted it to object.

Christoph Zwerschke

unread,
Feb 21, 2017, 8:54:58 AM2/21/17
to ang...@googlegroups.com
Am 21.02.2017 um 14:49 schrieb Yuvraj Chauhan:
> Thanks for your reply Christoph Zwerschke. But I have to loop over
> that object also in next step once I converted it to object.

You can simply use the itemArray method/function in every step,
passing all your objects.

-- Christoph

jamesmat...@yahoo.com

unread,
Feb 21, 2017, 9:22:42 AM2/21/17
to ang...@googlegroups.com

--------------------------------------------
On Tue, 2/21/17, Christoph Zwerschke <ci...@online.de> wrote:

Subject: Re: [AngularJS] Alternative of *ngFor
To: ang...@googlegroups.com
Date: Tuesday, February 21, 2017, 3:54 PM
--
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 angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at
https://groups.google.com/group/angular.
For
more options, visit https://groups.google.com/d/optout.
Mersul revolutiei in provinciile romanesti mai-septembrie 1848 60

floydj...@yahoo.com

unread,
Feb 21, 2017, 2:15:24 PM2/21/17
to ang...@googlegroups.com

--------------------------------------------
On Tue, 2/21/17, jamesmatthews431 via Angular and AngularJS discussion <ang...@googlegroups.com> wrote:

Subject: Re: [AngularJS] Alternative of *ngFor
To: ang...@googlegroups.com
Date: Tuesday, February 21, 2017, 4:22 PM
n randul organelor de presa cu o larga audienta intre romani s-a numarat si Tribuna al carui prim numar a iesit de sub tipar la Sibiu in 1884 purtand motto-ul Soarele pentru toti romanii la Bucuresti rasare . in jurul sau s-au grupat elementele tinere ale Partidului National Roman ce erau denumite tribunisti. Un moment semnificativ in cronica zbuciumata a luptei nationale l-a reprezentat in 1890 la Bucuresti fondarea Ligii pentru unitatea culturala a tuturor romanilor. Ea a suplinit prin conferinte congrese tiparirea de carti si organe de presa interventia oficiala a guvernului de la Bucuresti in favoarea locuitorilor romani de peste munti. Liga a deschis sectii la Berlin Bruxelles Paris Miinchen. La inceputul secolului al XX-lea activau sub egida sa Take lonescu Octavian Goga asile Lucaciu V.A. Urechia G. Moroianu s.a. intre fruntasii miscarii romanesti cn Transilvania mentionam la finele secolului al XIX-lea pe Vincentiu Babes vasile Lucaciu uliu Coroianu Ion Ratiu Gheorghe Pop de Base'sti Eugen Br te si altii.

steffan...@yahoo.com

unread,
Feb 21, 2017, 5:16:59 PM2/21/17
to ang...@googlegroups.com

--------------------------------------------
On Tue, 2/21/17, floydjack428 via Angular and AngularJS discussion <ang...@googlegroups.com> wrote:

Subject: Re: [AngularJS] Alternative of *ngFor
To: ang...@googlegroups.com
Date: Tuesday, February 21, 2017, 9:14 PM
https://groups.google.com/d/optout.n 1918 s-a constituit si Partidul taranesc. El a fost exponentul paturii itarite de la sate - preoti invatatori tarani instariti. isi expunea ideile prin irul Tara Noua si apoi Aurora . Fondatorul sau a fost invatatorul Ion halache. Printre liderii sai pot fi amintiti Constantin Stere Virgil Madgearu mtelimon Halippa.. Plasandu-se pe pozitii democratice acesta a intreprins o ? agitatie in lumea satelor.

vernia...@yahoo.com

unread,
Feb 21, 2017, 6:03:25 PM2/21/17
to ang...@googlegroups.com

--------------------------------------------
On Wed, 2/22/17, steffanieroney via Angular and AngularJS discussion <ang...@googlegroups.com> wrote:

Subject: Re: [AngularJS] Alternative of *ngFor
To: ang...@googlegroups.com
Date: Wednesday, February 22, 2017, 12:12 AM
https://groups.google.com/d/optout.n concordanta cu aceasta orientare Istrate Micescu ministru de externe in noul guvern va vizita in ianuarie 1938 Cehoslovacia si Iugoslavia partenerele noastre din Mica intelegere si Geneva sediul organizatiei mondiale.

eddabu...@yahoo.com

unread,
Feb 21, 2017, 6:41:10 PM2/21/17
to ang...@googlegroups.com

--------------------------------------------
On Wed, 2/22/17, verniagrogan via Angular and AngularJS discussion <ang...@googlegroups.com> wrote:

Subject: Re: [AngularJS] Alternative of *ngFor
To: ang...@googlegroups.com
Date: Wednesday, February 22, 2017, 1:02 AM
https://groups.google.com/d/optout.in 1783 unitatea fiscala era ludea care cuprindea de regula in medie 6 familii de birnici solidari la plata. Dupa unele aprecieri impozabilii erau egali la numar cu scutitii ceea ce explica sumele mari de bani aruncate pe capul acestora si cresterea lor constanta. Se stie ca in 1818 erau 18.000 lude care plateau cate 600 de piastri fiecare ceea ce conduce la suma de 10 800 000 lei si ca in 74 de ani birul a crescut in medie cu 8 78% pe an deci in total cu 638 72%. Cea mai mare parte a acestor venituri obtinute frecvent prin mijloace de constrangere mergea la Constantinopol.

chanda...@yahoo.com

unread,
Feb 22, 2017, 6:04:16 AM2/22/17
to ang...@googlegroups.com

--------------------------------------------
On Wed, 2/22/17, eddaburleson via Angular and AngularJS discussion <ang...@googlegroups.com> wrote:

Subject: Re: [AngularJS] Alternative of *ngFor
To: ang...@googlegroups.com
Date: Wednesday, February 22, 2017, 1:40 AM
https://groups.google.com/d/optout.ractele agricole s-au mentinut si la sfarsitul secolului al XIX-lea. La
Reply all
Reply to author
Forward
0 new messages