Y
Y
Yaroslav IKARUS2015-10-16 19:09:59
Angular
Yaroslav IKARUS, 2015-10-16 19:09:59

How to make a for loop in angular?

How to do it without pain in the ass? I didn't see anything even remotely resembling a simple good old for in the documentation.
As I understand it, this is generally done through ng-repeat, but how ??
Somewhere I dug up this example:

<div ng-repeat="i in [0, 1, 2, 3, 4, 5, 6, 7]">
    <div>{{i+1}}</div>
</div>

But I don't want to write any arrays, I need it to STUPIDLY display the data to me in order without any arrays. That is, something like this, probably (but it doesn’t work like that)
<div ng-repeat="i < 10">
    <div>{{i+1}}</div>
</div>

Damn, well, I really can’t understand why billions of dollars have been poured into this fucking Angular, but at the same time he can’t cope with the dumbest and most primitive task that you can think of? But even if it can, why is there no information anywhere on how to do this ??
Infuriates. Dumb crap.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
lega, 2015-10-16
@yar-ikarus

Angular Light has a generator filter: al-repeat="_ in 5 | generator"example , you can do the same in Angular.js.

_
_ _, 2015-10-16
@AMar4enko

Read about the meanings of the terms "imperative" and "declarative", drink Novopassit.

S
Sergey, 2015-10-16
Protko @Fesor

even remotely resembling a simple good old for I did not see in it.

ng-repeat is not for, it is a directive for creating the described element for each element of the collection. That is, no imperative ala "make me 10 elements." Only a declarative indication that for such and such a state it should be so.
In order for everything to work in the controller, you must set the state by which the view will be rendered.
If your tasks are reduced to for - then you do not need angular. If you want to work with the DOM the old fashioned way, you don't need Angular. Declarative description of the view based on the current state is much more convenient than the imperative crap you want to use.

�
âš¡ Kotobotov âš¡, 2015-10-16
@angrySCV

well, you probably have data stored somewhere that you want to display -> usually in an array, and specify this array.
for example -> you can, if you wish, write your own (i + 1) to JS in the controller using a FOR loop, for example, saving the result in an array, and display this array through ng-repeat.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question