Advertisement
Shell_Casing

details component

Dec 12th, 2018
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 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.  
  16. constructor(private articleService: ArticleService,
  17. private router: Router,
  18. private activatedRoute: ActivatedRoute) { }
  19.  
  20. ngOnInit() {
  21. this.activatedRoute.params.subscribe(params => this.id = params.id);
  22. this.articleService.getOneArticle(this.id).subscribe(article => {
  23. console.log(article);
  24. this.article = article;
  25. });
  26. }
  27.  
  28. editArticle(id) {
  29. this.router.navigate([`/articles/edit/${id}`]);
  30. }
  31.  
  32.  
  33. deleteArticle(id) {
  34. if (confirm('You are about to permanently remove this article. Continue?')) {
  35. this.articleService.deleteArticle(id).subscribe(() => {
  36. console.log('delete article');
  37. });
  38. this.articleService.articles = this.articleService.articles.filter(article => article.id !== id);
  39. this.router.navigate(['/articles']);
  40. }
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement