http://plnkr.co/edit/aiGCPJEwTj0RWnuoCjsW?p=preview
我希望删除按钮仅显示该项目的弹出窗口。
您将如何处理?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;
};
}]);
事情是ng-repeat会创建自己的作用域,因此'popoverRemove'是每个作用域的局部变量。您可以通过向ng-repeat的特定元素的控制器发送上下文并将其设置为使用“ this”的值。
<button class="btn btn-default"
ng-mouseover="showPopover(this)"
ng-mouseleave="hidePopover(this)">Remove</button>
vs.showPopover = function(context) {
context.popoverRemove = true;
};
vs.hidePopover = function(context) {
context.popoverRemove = false;
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句