使用ng-click

时间:2017-01-05 18:07:19

标签: angularjs filtering

我希望用户能够点击四个已过滤的场景。我为每个场景都有一个不同的ng-repeat过滤器。

<div ng-model="topic0" ng-repeat="post in postCtrl.getAllPosts() | orderBy :'-votes' ">
        <div ng-model="topic1" ng-repeat=" post in postCtrl.getAllPosts() | filter:{topicId:'1'} | orderBy :'-votes'"> ">
            <div ng-model="topic2" ng-repeat=" post in postCtrl.getAllPosts() | filter:{topicId:'2'} | orderBy :'-votes'"> ">
                <div ng-model="topic3" ng-repeat=" post in postCtrl.getAllPosts() | filter:{topicId:'3'} | orderBy :'-votes'">

这些是我的按钮:

<a class="btn-flat topic" >All</a>
<a class="btn-flat topic">Inspire</a>
<a class="btn-flat topic">Show Off</a>
<a class="btn-flat topic">Share</a>

如何进行设置,以便仅在单击选项卡时触发每个过滤的ng-repeat场景。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

<a class="btn-flat topic" ng-click="postCtrl.topicId = undefined">All</a>
    <a class="btn-flat topic" ng-click="postCtrl.topicId = 1">Inspire</a>
    <a class="btn-flat topic" ng-click="postCtrl.topicId = 2">Show Off</a>
    <a class="btn-flat topic" ng-click="postCtrl.topicId = 3">Share</a>

<div ng-model="topic0" ng-repeat="post in postCtrl.getAllPosts() | orderBy :'-votes' | filter: { topicId: postCtrl.topicId}">