i write a simple angularJS code:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0-beta.1/angular.min.js"></script>
</head>
<body ng-app="myApp">
<script>
angular.module('myApp', []).controller('BooksController', function($scope){
$scope.books = [{'name':'aaa'}, {'name':'bbb'}, {'name':'ccc'}];
$scope.addBook = function(newBook){
$scope.books.push(newBook);
}
});
</script>
<div ng-controller="BooksController">
<ul>
<li ng-repeat="book in books">{{book.name}}</li>
</ul>
<input ng-model=aBook.name />
<a href=# ng-click="addBook(aBook)">add to list</a>
</div>
</body>
</html>
http://plnkr.co/edit/EIT32t8NgRiLchVXgooL?p=preview
when i add a new item to the list, it works correctly. but when i want to add another new item, the last item overwrite as you can see in the url. why? what happen?
aBooktobookdoesn't solve the problem as you can test at the address.