Sameer
Sameer

Reputation: 3506

How to display ng-repeat data with certain conditions - AngularJS

This is my json object response:

{
"draftType": "manualinput",
"senderdata": "123456789",
"senderName": "ifelse",
"message": "Hi",
"draftName": "Testing"
}

I am displaying this in UI using ng-repeat:

controllers.js:

$http({
   method: 'GET',
   url: '/api/getdraft'

}).then(function (response) {
   $scope.drafts = response.data;
}, function (response) {
   console.log(response);
});

my code:

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

But i need some condition, if my draftType object key have string called "manualinput" i want to display datas,

sometimes draftType will come as "contactinput",

so i dont want to display if my draftType is not equal to "manualinput".

Is this possible to do?

Upvotes: 0

Views: 52

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222542

You need to use ng-if with ng-repeat

CODE:

tr(ng-repeat='draft in drafts' ng-if="draft.draftType === 'manualinput'")

Upvotes: 2

Gitesh Purbia
Gitesh Purbia

Reputation: 1104

You can add ng-if with ng-repeat. please try with this.

tr(ng-repeat='draft in drafts') data-ng-if="draft.draftType === 'manualinput'"
 td {{draft.draftName}}
 td {{draft.senderName}}
 td {{draft.message}}

Upvotes: 2

Related Questions