function ExampleController($scope){ $scope.person = { name: 'Kalle', age: 22, happy: true, friends: ['Henri', 'Arto', 'Elina', 'Jorma'] }; $scope.addFriend = function(){ $scope.person.friends.push($scope.newFriend); } $scope.removeFriend = function(index){ $scope.person.friends.splice(index, 1); } }
<div ng-app> <div ng-controller="ExampleController"> <ul ng-repeat="friend in person.friends"> <li>{{friend}} <button ng-click="removeFriend($index)">Poista</button></li> </ul> <input type="text" ng-model="newFriend"> <button ng-click="addFriend()">Lisää ystävä</button> </div> </div>