neiza neiza - 5 months ago 13
JSON Question

Show a region on page if data from json equal to true with Ionic and Angular

I'm creating an ionic app and there are variables I request from a php page through the Ionic controller. From the variables I get, I have a field called

active
which either be
yes
or
no
for each user after log on.
What I want to achieve is, there is a div on the page called "activediv" and I want that div show only if the variable from the json = yes.

.controller('useraccount_ctrl', ['$scope', '$http', function($scope, $http) {
$http.get('http://localhost/myapp/app_ion/templates/user/user_account.php').success(function(data) {
$scope.userdata = (data);
});
}])


HTML

<ion-content class="has-subheader">

<ion-list class="list card" ng-repeat="item in userdata">
<ion-item href="#/tab/source/{{item.profile_id}}">
<div class="item item-avatar-big">
<img src="../usr_up_img/{{item.profile_pix}}">
<h2>{{item.fname}}</h2>
<p>{{item.country}}</p>
<p>{{item.curr_city}}</p>
<div id="activediv">{{item.active}}</div>
</div>
</ion-item>
</ion-list>

</ion-content>


JSON

[{"fname":"Nicholas","country":"India","curr_city":"East Legon","profile_id":"1298","profile_pix":"173333297082.jpg","active":"yes"}]

Answer

Try this

<div id="activediv" ng-if ="item.active == 'yes'">{{item.active}}</div>
Comments