D
D
Dmitry Sokolov2016-06-26 14:29:41
Angular
Dmitry Sokolov, 2016-06-26 14:29:41

How to save value from ng-repeat loop?

Good afternoon!
Tell me why saving an object inside ng-repeat is not available outside this loop?
I need to display the value where the comment "//is not displayed" now

<div class="container">
    <div ng-controller="reviewCtrl">
        <div class="col-sm-6 col-xs-12" ng-repeat='review in reviews'>
            <div ng-controller="reviewImgCtrl">
                <div class="row">
                    <div class="col-xs-12" ng-repeat='reviewImage in reviewImages  | filter:{id_review:review.id} | limitTo:1'>
                        <img src="{{clientURL + reviewImage.foto}}" class="review-main-foto">
                        {{mainFotoFactory.main}} //не выводится
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-3" ng-repeat='reviewImage in reviewImages  | filter:{id_review:review.id} | limitTo:4'>
                        <img ng-click="mainFotoFactory.main = clientURL + reviewImage.foto" src="{{clientURL + reviewImage.foto}}" class="review-more-foto">
                        {{mainFotoFactory.main}} // выводится
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

app.controller('reviewImgCtrl', function ($http, $scope, reviewImgFactory, mainFotoFactory) {
    $scope.reviewImgFactory = reviewImgFactory;
    $http.get($base + 'review-imgs')
        .success(function (result) {
            $scope.reviewImages = result;
        })
        .error(function (result) {
        });
});

app.factory('mainFotoFactory', function () {
    return {
        main: ''
    }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sokolov, 2016-06-27
@Dm-Sok

Understood. Forgot to specify in the controller$scope.reviewFactory = reviewFactory;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question