简体   繁体   English

如果json中的数据在Ionic和Angular中等于true,则在页面上显示区域

[英]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. 我正在创建一个离子应用程序,并且通过Ionic控制器从php页面请求了一些变量。 From the variables I get, I have a field called active which either be yes or no for each user after log on. 从得到的变量中,我有一个名为active的字段,登录后每个用户可以为yesno 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. 我要实现的是,页面上有一个称为“ activediv”的div,并且我希望仅当json = yes的变量时才显示该div。

.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 的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 JSON格式

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

尝试这个

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

use ng-if 使用ng-if

<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 ng-if ="item.profile_pix && item.active =='yes'" src="../usr_up_img/{{item.profile_pix}}">
<h2 ng-if ="item.fname && item.active =='yes'">{{item.fname}}</h2>
<p ng-if ="item.country && item.active =='yes'">{{item.country}}</p>
<p ng-if ="item.curr_city && item.active =='yes'">{{item.curr_city}}</p>
<div id="activediv" ng-if ="item.active =='yes'">{{item.active}}</div>
</div>
</ion-item>
</ion-list>

Pravesh's answer is good. Pravesh的回答很好。

You can also use ng-show and it will just hide or show your div's content: 您还可以使用ng-show ,它只会隐藏或显示div的内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM