Advertisement
Shell_Casing

detail component

Dec 12th, 2018
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3.  
  4. import { ArticleService } from '../../article.service';
  5.  
  6. @Component({
  7. selector: 'app-detail',
  8. templateUrl: './detail.component.html',
  9. styleUrls: ['./detail.component.css']
  10. })
  11. export class DetailComponent implements OnInit {
  12. id: string;
  13. article: any = {};
  14.  
  15. constructor(private articleService: ArticleService,
  16. private router: Router,
  17. private activatedRoute: ActivatedRoute) { }
  18.  
  19. ngOnInit() {
  20. this.activatedRoute.params.subscribe(params => this.id = params.id);
  21. this.articleService.getOneArticle(this.id).subscribe(article => {
  22. console.log(article);
  23. this.article = article;
  24. });
  25. }
  26.  
  27. editArticle(id) {
  28. this.router.navigate([`/articles/edit/${id}`]);
  29. }
  30.  
  31.  
  32. deleteArticle(id) {
  33. if (confirm('You are about to permanently remove this article. Continue?')) {
  34. this.articleService.deleteArticle(id).subscribe(() => {
  35. this.router.navigate(['/articles']);
  36. });
  37. }
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement