Good day, I am just wodering if it is possible to do the logic of *ngFor in the typescript? I want to loop the data from my JSON API in the typescript just like what *ngFor does in the HTML. Hope you can help me. Thank you in advance.
Asked
Active
Viewed 3,890 times
-5
-
1https://stackoverflow.com/questions/684672/how-do-i-loop-through-or-enumerate-a-javascript-object – msanford Nov 22 '17 at 16:39
-
1what do you mean? *ngFor is template syntax use in html – phonemyatt Nov 22 '17 at 16:39
-
1An JS or JSON array has `forEach` https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array – Günter Zöchbauer Nov 22 '17 at 16:40
-
The *ngFor is a tipical thing of Angular. Do you use it? – H. Pauwelyn Nov 22 '17 at 16:42
-
@msanford the question is related to object´s key iteration, not arrays – Jota.Toledo Nov 22 '17 at 16:45
-
@Jota.Toledo I don't understand your remark. (1) What leads you to that conclusion? The question is about JSON, which can be only an array (`JSON.parse("[]")` is valid). (2) the question I linked is _specifically about object iteration_. – msanford Nov 22 '17 at 17:57
-
@Patrick, what are you asking? Please, put your question clearly and put some codes. Try to specify what you have tried and what are you asking for? – Mahi Nov 22 '17 at 18:29
1 Answers
1
*ngFor is used on template to repeat over elements in array. If you want to loop over items in typescript i.e in TS
, you can do this way
for(let item of this.result){
}

Sajeetharan
- 216,225
- 63
- 350
- 396
-
2Do you srsly need to add an answer for this question, which shows 0 effort on research? Come on – Jota.Toledo Nov 22 '17 at 16:46
-
@Jota.Toledo This comment, however, I agree with heartily. It's a half answer, at that. – msanford Nov 22 '17 at 17:58