-
Notifications
You must be signed in to change notification settings - Fork 14
/
blog-card.component.ts
60 lines (51 loc) · 1.46 KB
/
blog-card.component.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { Component, OnInit } from '@angular/core';
import { BlogService } from 'src/app/services/blog.service';
import { Post } from 'src/app/models/post';
import { ActivatedRoute } from '@angular/router';
import { AppUser } from 'src/app/models/appuser';
import { AuthService } from 'src/app/services/auth.service';
@Component({
selector: 'app-blog-card',
templateUrl: './blog-card.component.html',
styleUrls: ['./blog-card.component.scss']
})
export class BlogCardComponent implements OnInit {
config: any;
pageSizeOptions = [];
blogPost: Post[] = [];
appUser: AppUser;
constructor(
private blogService: BlogService,
private route: ActivatedRoute,
private authService: AuthService) {
this.authService.appUser$.subscribe(appUser => this.appUser = appUser);
this.pageSizeOptions = [2, 4, 6];
const pageSize = localStorage.getItem('pageSize');
this.config = {
currentPage: 1,
itemsPerPage: pageSize ? +pageSize : this.pageSizeOptions[0]
};
}
ngOnInit() {
this.route.params.subscribe(
params => {
this.config.currentPage = +params['pagenum'];
this.getBlogPosts();
}
);
}
getBlogPosts() {
this.blogService.getAllPosts().subscribe(result => {
this.blogPost = result;
});
}
delete(postId) {
if (confirm('Are you sure')) {
this.blogService.deletePost(postId).then(
() => {
alert("Blog deleted successfully");
}
);
}
}
}