Last active
September 14, 2019 17:44
-
-
Save dileno/64fb985e4607b3c561e6ea9ea91c5b8a to your computer and use it in GitHub Desktop.
BlogPostsComponent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
import { BlogPostService } from '../services/blog-post.service'; | |
import { BlogPost } from '../models/blogpost'; | |
@Component({ | |
selector: 'app-blog-posts', | |
templateUrl: './blog-posts.component.html', | |
styleUrls: ['./blog-posts.component.scss'] | |
}) | |
export class BlogPostsComponent implements OnInit { | |
blogPosts$: Observable<BlogPost[]>; | |
constructor(private blogPostService: BlogPostService) { | |
} | |
ngOnInit() { | |
this.loadBlogPosts(); | |
} | |
loadBlogPosts() { | |
this.blogPosts$ = this.blogPostService.getBlogPosts(); | |
} | |
delete(postId) { | |
const ans = confirm('Do you want to delete blog post with id: ' + postId); | |
if (ans) { | |
this.blogPostService.deleteBlogPost(postId).subscribe((data) => { | |
this.loadBlogPosts(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment