0

What I want to do is to create 2 angular tables where I display tasks. In the first table I want to show all tasks which are not assigned to user and in the second tab I want to show all tasks which are assigned to user

UsersDTO is array, I may have more users assigned to the same task.

My html code looks like this. This is tab where I got all tasks with assigned user to it. I am not pretty sure why this is working, but I assume it somehow looks into property and check if there is anything.

enter image description here

<tbody>
    <tr ng-repeat="task in project.ProjectTasksDTO | filter: {UsersDTO: {}}">
         <td>{{task.Id}}</td>
         <td>{{task.Title}}</td>
         <td>{{task.Text}}</td>
         <td>{{task.Description}}</td>
         <td><p ng-repeat="user in task.UsersDTO">{{user.UserName}}</p></td>
         <td>{{task.Status}}</td>                                                  
         <td>{{task.CreatedBy}}</td>
         <td><button class="btn-info" ng-click="editUser(user);">Profile</button></td>
    </tr>
</tbody>

Is there a way how to tell to filter in ng-repeat that UsersDTO is null or empty, something like in code below.

enter image description here

<tbody>
    <tr ng-repeat="task in project.ProjectTasksDTO | filter: {UsersDTO: {null}}">
         <td>{{task.Id}}</td>
         <td>{{task.Title}}</td>
         <td>{{task.Text}}</td>
         <td>{{task.Description}}</td>
         <td><p ng-repeat="user in task.UsersDTO">{{user.UserName}}</p></td>
         <td>{{task.Status}}</td>                                                  
         <td>{{task.CreatedBy}}</td>
         <td><button class="btn-info" ng-click="editUser(user);">Profile</button></td>
    </tr>
</tbody>
5
  • Not sure if this can be done without a custom filter function - any reason why you wouldn't use one? Commented Jan 24, 2017 at 13:11
  • I have no specific reason for it, but i was curious if something like this could be done with ng-repeat filter Commented Jan 24, 2017 at 13:15
  • Could you check this post? stackoverflow.com/questions/18644412/angularjs-filter-not-null Commented Jan 24, 2017 at 13:17
  • @Everton Santos Thats exactly what i was looking for. Thanks Commented Jan 24, 2017 at 13:27
  • @Martin you're welcome.. I needed it before Commented Jan 24, 2017 at 14:00

1 Answer 1

0

Hi you can do it this way without a the need for a function.

<div ng-repeat="task in project.ProjectTasksDTO | filter:{UsersDTO.length: 0}:true">

<div ng-repeat="task in project.ProjectTasksDTO | filter:{UsersDTO.length: 0}:false">

Altough keep in mind that the :true and :false notation is actually an angular specific shorthand notation and will be replaced with function(actual,expected) in a literal comparison to see if these match yes:true or no:false

Fidle

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

3 Comments

Hi, this looks also like a very nice solution for this, but it throws me a syntax Error: Token '.' is unexpected, expecting [}] at column 39 of the expression [project.ProjectTasksDTO | filter:{task.UsersDTO.length: 0}:true] starting at [.UsersDTO.length: 0}:true].
Are you sure its not deprecated? Anytime i use dot in expression it just throw an error. I solved this already with using ng-if, something like this: <tr ng-repeat="task in project.ProjectTasksDTO" ng-if="task.UsersDTO != null"> but i had to do extra modifications on my server side to send null to my objects when they are empty
@Martin I added a plunkr to clarify

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.