ng-show显示所有项目

时间:2016-03-31 10:37:28

标签: javascript angularjs ng-show ng-hide

继续使用angularjs,现在遇到ng-show问题,点击它会显示所有隐藏数据。据我所知,我需要指定我想要显示的点击项目的ID,从我的例子中我使用具有布尔值的ng-model,然后点击它改变为true,这就是为什么它&# 39;显示所有项目。请告诉我,我怎样才能显示我选择的项目?

<div class="list-group" ng-click="SetItemVisible()" ng-repeat="q in feed">
    <a href="" class="list-group-item">
        <h4 ng-model="showItem" class="list-group-item-heading">{{q.title}}</h4>
        <p ng-show="showItem" value="true" class="list-group-item-text">{{q.body}}</p>
    </a>
</div>

和js:

$scope.SetItemVisible = function () {
    if (!$scope.showItem) {
        $scope.showItem = true;
    } else {
        $scope.showItem = false;
    }
}

$scope.feed = [];

function getRssItems() {
    rssFeedService.getFeed().then(function (results) {
        $scope.feed = results.data;

    }, function (error) {
        //alert(error.data.message);
    });
}

3 个答案:

答案 0 :(得分:1)

<div class="list-group" ng-click="q.showItem != q.showItem" ng-repeat="q in feed">
    <a href="" class="list-group-item">
        <h4 ng-model="showItem" class="list-group-item-heading">{{q.title}}</h4>
        <p ng-show="q.showItem" value="true" class="list-group-item-text">{{q.body}}</p>
    </a>
</div>

答案 1 :(得分:1)

你可以通过以下方式做到:

exec sp_executesql @blockstring, N'@blogcount int output', @blogcount = @blockcount OUTPUT;
select @blockcount

如需直播演示,请点击此处:http://plnkr.co/edit/ApI9eb8eQlBdoMUkn8do?p=preview

答案 2 :(得分:1)

假设遵循饲料的JSON

 [
      {
        "title":"test1",
        "body":"test body 1",
        "show":false
      },
      {
        "title":"test2",
        "body":"test body 2",
         "show":false
      }
    ]

HTML

<body ng-controller="MainCtrl">

    <div class="list-group" ng-repeat="q in feed">
    <a class="list-group-item">
        <h4 ng-click="q.show=!q.show" class="list-group-item-heading">{{q.title}}</h4>
        <p ng-show="q.show" value="true" class="list-group-item-text">{{q.body}}</p>
    </a>
</div>

JS

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $http) {
  $scope.feed = [];

    $http.get('feed.json').then(function (results) {
        $scope.feed = results.data;

    }, function (error) {
        //alert(error.data.message);
    });

});

查看here