I'm having trouble removing contacts from my Phonebook app. Every time I use the deletePerson function, it deletes all contacts except the one I want to remove. Can someone please help me identify where I'm going wrong?
Here is a snippet of my contacts section:
<ul class="people-list">
<li showhideoptions ng-repeat="person in people | filter: search |
orderBy: 'name' | orderBy:'friend':true">
<h4>
<span ng-show="person.friend==true" class="icon-star icon-left"></span>
<span ng-show="person.friend==false" class="icon-user icon-left"></span>
{{person.name}}
<span ng-click="deletePerson($index)"
class="icon-remove pull-right"></span>
</h4>
</li>
</ul>
This is the main controller along with the factory:
var app = angular.module('contactList');
app.factory('simpleFactory', function(){
var people = [
{name: 'Collin', city: 'Omaha', friend: false},
{name: 'Alice', city: 'New York', friend: false},
{name: 'Pasha', city: 'Moscow', friend: true},
{name: 'Denis', city: 'St. Pete', friend: true}
];
var factory = {};
factory.getPeople = function() {
return people;
};
return factory;
});
app.controller('MainController', function ($scope, simpleFactory) {
$scope.people = [];
init();
function init() {
$scope.people = simpleFactory.getPeople();
}
$scope.addPerson = function() {
$scope.people.push(
{ name: $scope.newPerson.name,
city: $scope.newPerson.city,
friend: false
});
};
$scope.deletePerson = function($index) {
$scope.people.splice($index, 1);
}
});
UPDATE:
I've realized that the filter applied here:
| filter: search | orderBy: 'name' | orderBy:'friend':true"
Is causing issues with the deletion process. If anyone has advice on how to resolve this problem, I would greatly appreciate it!