我在前端设置了下拉按钮,现在只有在选择了下拉项时,我才必须在单独的内容块中显示我的数组。
我该怎么做?
这是我的plunker
HTML
<div ng-controller="DropdownCtrl">
<div class="row">
<div class="col-md-12">
<ul class="content">
<li ng-repeat= 'task in tasks'>
</li>
</ul>
</div>
</div>
<!-- Here goes dropdown menu !-->
<div class="btn-group" dropdown="" is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-default btn-xl" dropdown-toggle="" ng-disabled="disabled">
Options <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="single-button">
<li role="menuitem">
<a href="javascript:void(false)" ng-click="show('tasks')">Display tasks</a>
</li>
</ul>
</div>
</div>
的js
var myApp = angular.module('myApp', ['ui.bootstrap']);
myApp.controller('DropdownCtrl', function ($scope) {
$scope.tasks = [
{title:'First Task'},
{title: 'Second Task'}
];
});
答案 0 :(得分:1)
我建议你在每个任务元素中添加selected
属性,这将显示当前元素是否已被选中。根据您在selected
上执行ng-repeat
时可以对tasks
进行过滤。
<强>标记强>
<div class="col-md-12">
<div ng-show="filteredTask.length > 0">Below are selected Tasks</div>
<div ng-show="filteredTask.length == 0">No task selected</div>
<ul class="content">
<li ng-repeat= 'task in filteredTask = ( tasks | filter : {selected: true})'>
{{task.title}}
</li>
</ul>
</div>
<ul class="dropdown-menu" role="menu" aria-labelledby="single-button">
<li role="menuitem" ng-repeat="task in tasks">
<a href="javascript:void(false)" ng-click="task.selected = !task.selected">{{task.title}}</a>
</li>
</ul>