M
M
mitaichik2016-01-11 11:32:52
Angular
mitaichik, 2016-01-11 11:32:52

Is it possible to create a variable inside ng-repeat?

Hello! We have some code like this:

<div ng-repeat="deliveryType in deliveryTypes">
    <div ng-if="shop.getPropertiesForDeliveryType(deliveryType)">
        <div>{{shop.getPropertiesForDeliveryType(deliveryType).price}}</div>
        <div>{{shop.getPropertiesForDeliveryType(deliveryType).comment}}</div>
    <div>
</div>

As you can see, shop.getPropertiesForDeliveryType(deliveryType) is constantly called in the loop. It was logical to execute it once per iteration and store it in a variable. Can this be done in Angular?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mitaichik, 2016-01-11
@mitaichik

In general, ng-init exists for these purposes.

N
Nicholas, 2016-01-11
@healqq

Well, get your array of objects in the controller and already do ng-repeat on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question