Home AngularJs displaying ng-repeat data with some conditions
Reply: 3

AngularJs displaying ng-repeat data with some conditions

Mohamed Sameer
1#
Mohamed Sameer Published in 2018-01-13 06:41:04Z

This is my JSON object response:

{
"senderdata": "123456789",
"senderName": "ifelse",
"message": "Hi",
"draftName": "empty"
}

I am displaying this in UI using ng-repeat:

I am getting this json response in $scope.drafts.

my code:

tr(ng-repeat='draft in drafts')
 td {{draft.draftName}}
 td {{draft.senderName}}
 td {{draft.message}}

But I need some condition,

if my draftName object key have string called "empty" I don't want to display data.

Sajeetharan
2#
Sajeetharan Reply to 2018-01-13 06:47:21Z

Juse use != condition with ng-if

tr(ng-repeat='draft in drafts' ng-if="draft.draftName !== 'empty'")
NTP
3#
NTP Reply to 2018-01-13 06:50:19Z

You can filter your ng-repeat by draft name to display items only when draftName is not empty

<div ng-repeat="item in data | filter:{ draftName: '!empty'}">
  {{item.senderName}}-{{item.senderdata}}-{{item.draftName}}
</div>

demo

Shubham Pramanick
4#
Shubham Pramanick Reply to 2018-01-13 06:54:32Z

tr(ng-repeat='draft in drafts')

td {{draft.draftName=="empty"?"":draft.draftName}}

td {{draft.senderName}}

td {{draft.message}}

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304061 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO