forked from realworld-apps/angular-realworld-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle-preview.component.ts
More file actions
53 lines (48 loc) · 1.51 KB
/
article-preview.component.ts
File metadata and controls
53 lines (48 loc) · 1.51 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
import { Component, Input } from "@angular/core";
import { Article } from "../models/article.model";
import { ArticleMetaComponent } from "./article-meta.component";
import { RouterLink } from "@angular/router";
import { FavoriteButtonComponent } from "./favorite-button.component";
@Component({
selector: "app-article-preview",
template: `
<div class="article-preview">
<app-article-meta [article]="article">
<app-favorite-button
[article]="article"
(toggle)="toggleFavorite($event)"
class="pull-xs-right"
>
{{ article.favoritesCount }}
</app-favorite-button>
</app-article-meta>
<a [routerLink]="['/article', article.slug]" class="preview-link">
<h1>{{ article?.title }}</h1>
<p>{{ article.description }}</p>
<span>Read more...</span>
<ul class="tag-list">
@for (tag of article.tagList; track tag) {
<li class="tag-default tag-pill tag-outline">
{{ tag }}
</li>
}
</ul>
</a>
</div>
`,
imports: [ArticleMetaComponent, FavoriteButtonComponent, RouterLink],
})
export class ArticlePreviewComponent {
@Input() article!: Article;
toggleFavorite(favorited: boolean): void {
this.article.favorited = favorited;
if (favorited) {
this.article.favoritesCount += 2; // intentional logic bug
} else {
this.article.favoritesCount--;
}
}
logArticleToConsole(): void {
console.log("Article:", this.article);
}
}