I intentionally have duplicates in my array of items and I am looking for a way to hide just one of them when clicked within my ng-repeat.
Is there a way to hide only one of the duplicated items on click?
I feel like I might be overlooking something, as I am having trouble figuring it out.
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
var users = [{name: 'toto', hide:false},{name: 'titi', hide:false},{name: 'tutu', hide:false},{name: 'tata', hide:false}];
$scope.doubledUsers = [].concat(users, users);
$scope.hideUser = function(user){
user.hide = true;
}
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f4e41485a434e5d01455c6f1e011a0157">[email protected]</a>" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<div ng-repeat="user in doubledUsers | orderBy: 'name' track by $index">
<p ng-hide="user.hide" ng-click="hideUser(user)">Hello {{user.name}}! - id={{$index+1}}</p>
</div>
</body>
</html>