0

This question is a little hard to explain so i will try with my actual code to show the example. I am using ng-repeat using the syntax "ng-repeat='a in achievements = ( | achievements entity is not defined until within the ng-repeat that is not an option. i am forced to place it AFTER the ng-repeat has ended. Is there a different way to accomplish this, to be able to reference the filtered contents of the object before or within the ng-repeat (but without having it actually repeated)

            <div style="padding:10px;margin-bottom:10px;" ng-repeat="a in achievments =(userAchievementConfig.achievements 
                                                                    | filter:userAchievementConfig.filters.search 
                                                                    | filter:{UserTeam:userAchievementConfig.filters.team}
                                                                    | filter:{UserDept:userAchievementConfig.filters.dept})"
                                                    ng-if="$index >= userAchievementConfig.startNum && $index <= userAchievementConfig.endNum">
            <div ng-if="achievements.length == 0" class="alert alert-info text-center">No users match your current filter</div>
            <div class="col-sm-2">
                <img ng-if="a.picture" data-ng-src="data:image/png;base64,{{a.picture}}" border=0 class='img-rounded pull-left' style="max-height:125px;max-width:100%;" >
                <div ng-if="!a.picture" style="height:125px;width:100%;padding:3px;background-color:#CCC;"></div> 
            </div>
            <div class="col-sm-10">
                <h4 ng-bind="a.UserName"></h4>
                <span ng-bind="a.sComments"></span>
                <br><i> - <span ng-bind="a.RequestedByName"></span> in <span ng-bind="a.timeSubmitted"></span></i>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="col-sm-6" ng-if="!userAchievementConfig.filters.search">
            <ul uib-pagination total-items="userAchievementConfig.achievements.length"  boundary-link-numbers="true" max-size="3" ng-model="userAchievementConfig.pageNum" class="pagination-sm nomargin" items-per-page="userAchievementConfig.itemsPerPage"></ul>
        </div>
        <div class="col-sm-6" ng-if="!userAchievementConfig.filters.search">
            Showing {{userAchievementConfig.startNum+1}} - {{userAchievementConfig.endNum+1}} of {{userAchievementConfig.achievements.length}} achievements
        </div>
        <div class="clearfix"></div>
4
  • it's still not really clear what you are trying to accomplish, or what your issue is here. Commented Apr 6, 2017 at 0:17
  • I want to move pagination before the ng-repeat, but still be able to reference the filtered list. But that filtered list doesn't exist until the ng-repeat is started Commented Apr 6, 2017 at 0:35
  • you could use ng-repeat with an alias, eg. ng-repeat = a in userAchievementConfig.achievements | allYourFilters as achievements, which would make achievements a $scope property. Commented Apr 6, 2017 at 0:43
  • I should have figured this out before .. i didn't make the connection that the alias was within the scope of the ng-repeat (since i can reference it outside and after the ng-repeat). i was unable to refer to it BEFORE the ng-repeat as $scope.achievements, but as you said once i made it part of an object, like ng-repeat = a in $scope.userAchievementsConfig.filteredachievements = (<source> | <filters>) then it started working :( Commented Apr 6, 2017 at 0:55

1 Answer 1

1

You can get filtered item without ng-repeat as below code

$scope.filteredItems = $scope.$eval("userAchievementConfig.achievements  | filter:userAchievementConfig.filters.search | filter:{UserTeam:userAchievementConfig.filters.team}| filter:{UserDept:userAchievementConfig.filters.dept}");
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I was not aware of doing it this way
Please mark it as answer if it resolves your issue so that others can get benefits
I will test it and mark as answer if it works for my case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.