angularjs – 如何针对ng-repeat中的特定项目进行ng-show?

前端之家收集整理的这篇文章主要介绍了angularjs – 如何针对ng-repeat中的特定项目进行ng-show?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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;
        };

    }]);

解决方法

Plunker给你

问题是ng-repeat创建了它自己的范围.因此,’popoverRemove’是每个范围的局部变量.你可以通过向ng-repeat的特定元素的控制器发送上下文来设置true或false为局部变量并设置它价值使用’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;
};

猜你在找的Angularjs相关文章