http://plnkr.co/edit/aiGCPJEwTj0RWnuoCjsW?p=preview如何定位ng-repeat中特定項目的ng顯示?
我想刪除按鈕只顯示該項目的酥料餅。
你會怎麼做呢? HTML:
<li ng-repeat="acc in accounts">
<div class="well well-sm">
<div class="popover-remove" ng-show="popoverRemove">Click to remove item</div>
<h4>{{acc.label}}</h4>
<button class="btn btn-default"
ng-mouseover="showPopover()"
ng-mouseleave="hidePopover()">Remove</button>
</div>
</li>
角控制器:
var app = angular.module('myApp', [])
.controller('AccountsCtrl',
['$scope',
function($scope) {
var vs = $scope;
vs.accounts = [
{
id: '1',
label: 'Bitage'
},
{
id: '2',
label: 'Blockchain.info'
},
{
id: '3',
label: 'Coinbase wallet'
},
{
id: '4',
label: 'Xapo wallet'
}
];
vs.showPopover = function() {
vs.popoverRemove = true;
};
vs.hidePopover = function() {
vs.popoverRemove = false;
};
}]);
嘗試[$指數](https://docs.angularjs.org/api/ng/directive/ngRepeat)。 – 2015-04-01 16:45:53
[示例](http://plnkr.co/edit/F1QFgL65kj5v6q1dMGpM?p=preview)。 – 2015-04-01 16:49:03
@AustinMullins真棒:)但有一件事保持,如果你會在ng-repeat上使用過濾器,那麼$ index會改變,並且不會被應用(只是爲了防範)。 – squiroid 2015-04-01 16:53:36