1

I have this in html code:

<md-list>
  <md-list-item ng-repeat="schema in dash.filteredSchemas = (dash.items | filter: {name: dash.schemaListFilter}) | orderBy: 'schema.id'">
    <h4>{{ ::schema.name }}</h4>
  </md-list-item>
</md-list>
<div ng-show="dash.filteredSchemas.length">Empty</div>

The problem is that I don't see any results when using this syntax - where 10 results should be shown if filter in not filled.

Note: no console errors. Changing to:

<md-list>
  <md-list-item ng-repeat="schema in dash.items | filter: {name: dash.schemaListFilter} | orderBy: 'schema.id'">
    <h4>{{ ::schema.name }}</h4>
  </md-list-item>
</md-list>
<div ng-show="dash.filteredSchemas.length">Empty</div> 

Shows results but (obviously) not shows the empty message when filter applied and no result match.

What is wrong with that?!

2
  • how do u set dash.filteredSchemas on second example? Commented Jan 22, 2016 at 10:13
  • I don't, it's not working Commented Jan 22, 2016 at 10:14

1 Answer 1

1

If you want get filtered result but do not want to break original array you can use 'as' operation for ng-repeat...

<md-list>
  <md-list-item ng-repeat="schema in dash.items | filter: {name: dash.schemaListFilter} | orderBy: 'schema.id' as filteredData">
    <h4>{{ ::schema.name }}</h4>
  </md-list-item>
</md-list>
<div ng-show="filteredData.length">Empty</div>

so whenever you change your filter query the result will be set to 'filteredData' so you can use this array properties to achieve what you want...

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but how can I bind filteredData alias to my controller? meaning that I would be able to use it in other places like dash.filteredData?
if you really wants to set it on your vm alias you can watch its value as it is an element of scope...

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.