0

For example i have this repeat list:

<ul>
    <li class="suggestion-item" ng-repeat="item in suggestionList.items | filter: {id: 2} track by track(item)">{{item.text}}</li>
<ul>

Can i somehow (would be better without changing controller because it's a directive) check: if filter result is not empty - then display whole ul, if not, then hide ul. I mean something like:

<ul ng-if="(item in suggestionList.items | filter: {id: 2}).length > 0">
    <li class="suggestion-item" ng-repeat="item in suggestionList.items | filter: {id: 2} track by track(item)">{{item.text}}</li>
<ul>

2 Answers 2

2

You can assign the filter result to a variable

<ul ng-show="filterResult && filterResult.length">
    <li class="suggestion-item" ng-repeat="item in filterResult = (suggestionList.items | filter: {id: 2}) track by track(item)">{{item.text}}</li>
<ul>
Sign up to request clarification or add additional context in comments.

Comments

0

using $parent you can achieve it

<ul ng-show="suggestionListItem.length" >
 <li class="suggestion-item" ng-repeat="item in ($parent.suggestionListItem = (suggestionList.items | filter: {id: 2} track by track(item)))">{{item.text}}</li>
<ul>

Comments

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.