-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
107 lines (88 loc) · 1.87 KB
/
app.ts
File metadata and controls
107 lines (88 loc) · 1.87 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/// <reference path="typings/angular2/angular2.d.ts" />
import {
Component,
NgFor,
View,
bootstrap
} from "angular2/angular2";
class Article {
title: string;
link: string;
votes: number;
constructor(title, link)
{
this.title = title;
this.link = link;
this.votes = 0;
}
voteUp() {
this.votes +=1;
return false;
}
voteDown() {
this.votes -=1
return false;
}
domain() {
// var link = this.link.split('//')[1];
// return link.split('/')[0];
return this.link;
}
}
@Component({
selector: 'reddit-article',
properties: ['article'],
})
@View({
template: `
<article>
<div class="votes">{{ article.votes }}</div>
<div class="main">
<h2>
<a href="{{ article.link }}">{{ article.title }}</a>
<span>({{ article.domain() }})</span>
</h2>
<ul>
<li><a href (click)='article.voteUp()'>Upvote</a></li>
<li><a href (click)='article.voteDown()'>Downvote</a></li>
</ul>
</div>
</article>
`
})
class RedditArticle {
article: Article;
}
@Component({
selector: 'reddit'
})
@View({
template: `
<section class="new-link">
<div class="control-group">
<div><label for="title">Title:</label></div>
<div><input name="title" #newtitle></div>
</div>
<div class="control-group">
<div><label for="link">Link:</label></div>
<div><input name="link" #newlink></div>
</div>
<button (click)="addArticle(newtitle, newlink)">Submit Link</button>
</section>
<reddit-article
*ng-for="#article of articles"
[article]="article">
</reddit-article>
`,
directives: [RedditArticle, NgFor]
})
class RedditApp {
articles: Array<Article>;
constructor() {
this.articles = [new Article('Testing 1', 'http://www.google.com'), new Article('Testing 2', 'http://www.google.com')];
}
addArticle(title, link){
this.articles.push(new Article(title.value, link.value));
}
}
bootstrap(RedditApp);