How to configure ng-show on specific items in ng-repeat?

http://plnkr.co/edit/aiGCPJEwTj0RWnuoCjsW?p=preview

I want the delete button to display only the popover for this element .

How would you do that? 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>

Angular Controller:

    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;
        };

    }]);

enter image description here

+4
source share
3 answers

Plunker for you

, 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;
};
+4

:

well.show true/false, !

    <li ng-repeat="acc in accounts track by $index">
      <div class="well well-sm">
        <div class="popover-remove" ng-show="well.show">Click to remove item</div>
        <h4>{{acc.label}}</h4>
        <button class="btn btn-default"
                ng-mouseover="well.show=true"
                ng-mouseleave="well.show=false">Remove</button>
      </div>
    </li>

Plunker

+2

popOverRemove . . showPopover/hidePopover.

vs.accounts = [
    {
        id: '1',
        label: 'Bitage',
        popoverRemove: false
    },
    {
        id: '2',
        label: 'Blockchain.info',
         popoverRemove: false
    },
    {
        id: '3',
        label: 'Coinbase wallet',
       popoverRemove: false
    },
    {
        id: '4',
        label: 'Xapo wallet',
        popoverRemove: false
    }
];

http://plnkr.co/edit/uAjhiYTDyXIBmkxAQzzw?p=preview

+1

All Articles