-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
45 lines (38 loc) · 986 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {Component, View, bootstrap, NgFor} from 'angular2/angular2';
@Component({
selector: 'my-app'
})
@View({
template: `
<ul>
<li *ng-for="#movie of movies; #i = index">
{{ movie }}
<button (click)="removeMovie(i)">Remove Movie</button>
</li>
</ul>
<input #currname (keyup)="doneTyping($event)">
<button (click)="addMovie(currname.value)">Add Movie</button>
`,
directives: [NgFor]
})
class TodoList {
movies: Array<string>;
constructor() {
this.movies = JSON.parse(localStorage['movies']) || [];
}
addMovie(movie: string) {
this.movies.push(movie);
localStorage['movies'] = JSON.stringify(this.movies);
}
removeMovie(i: number) {
this.movies.splice(i, 1);
localStorage['movies'] = JSON.stringify(this.movies);
}
doneTyping($event) {
if($event.which === 13) {
this.addMovie($event.target.value);
$event.target.value = null;
}
}
}
bootstrap(TodoList);