Created
September 14, 2019 18:33
-
-
Save dileno/c3899560addc4989bc2a7f8778bddee4 to your computer and use it in GitHub Desktop.
Blog-post.component
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 { ActivatedRoute } from '@angular/router'; | |
import { Observable } from 'rxjs'; | |
import { BlogPostService } from '../services/blog-post.service'; | |
import { BlogPost } from '../models/blogpost'; | |
@Component({ | |
selector: 'app-blog-post', | |
templateUrl: './blog-post.component.html', | |
styleUrls: ['./blog-post.component.scss'] | |
}) | |
export class BlogPostComponent implements OnInit { | |
blogPost$: Observable<BlogPost>; | |
postId: number; | |
constructor(private blogPostService: BlogPostService, private avRoute: ActivatedRoute) { | |
const idParam = 'id'; | |
if (this.avRoute.snapshot.params[idParam]) { | |
this.postId = this.avRoute.snapshot.params[idParam]; | |
} | |
} | |
ngOnInit() { | |
this.loadBlogPost(); | |
} | |
loadBlogPost() { | |
this.blogPost$ = this.blogPostService.getBlogPost(this.postId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment