Skip to content

Instantly share code, notes, and snippets.

@dileno
Last active September 14, 2019 17:44
Show Gist options
  • Save dileno/64fb985e4607b3c561e6ea9ea91c5b8a to your computer and use it in GitHub Desktop.
Save dileno/64fb985e4607b3c561e6ea9ea91c5b8a to your computer and use it in GitHub Desktop.
BlogPostsComponent
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