blob: 23ad7dc03aad00c0c0eebf5f501e426686606451 [file] [log] [blame]
Simon Hunt335b2472014-12-08 16:52:18 -08001<!DOCTYPE html>
2<html ng-app="notesApp">
3<head>
4 <title>Notes App</title>
5 <script src="../../tp/angular.js"></script>
6 <style>
7 span {
8 background-color: #cce;
9 }
10 </style>
11</head>
12<body ng-controller="MainCtrl as ctrl">
13
14 <button ng-click="ctrl.changeNotes()">Change Notes</button>
15 <br/>
16
17 DOM Elements change at every click
18 <div ng-repeat="note in ctrl.notes1">
19 {{note.$$hashKey}}
20 <span class="label"> {{note.label}} </span>
21 <span class="author"> {{note.done}} </span>
22 </div>
23 <br/>
24
25 DOM Elements are reused at every click
26 <div ng-repeat="note in ctrl.notes2 track by note.id">
27 {{note.$$hashKey}}
28 <span class="label"> {{note.label}} </span>
29 <span class="author"> {{note.done}} </span>
30 </div>
31
32 <script type="text/javascript">
33 angular.module('notesApp', []).controller('MainCtrl', [
34 function () {
35 var self = this;
36 var notes = [
37 {id: 1, label: 'First note', done: false, someRandom: 31431},
38 {id: 2, label: 'Second note', done: false},
39 {id: 3, label: 'Finished third note', done: true}
40 ];
41 self.notes1 = angular.copy(notes);
42 self.notes2 = angular.copy(notes);
43
44 self.changeNotes = function () {
45 notes = [
46 {id: 1, label: 'Changed note', done: false, someRandom: 4242},
47 {id: 2, label: 'Second note', done: false},
48 {id: 3, label: 'Finished third note', done: true}
49 ];
50 self.notes1 = angular.copy(notes);
51 self.notes2 = angular.copy(notes);
52 }
53 }
54 ]);
55 </script>
56
57</body>
58</html>