Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { ActivatedRoute, Router } from '@angular/router';
- import { ArticleService } from '../../article.service';
- @Component({
- selector: 'app-detail',
- templateUrl: './detail.component.html',
- styleUrls: ['./detail.component.css']
- })
- export class DetailComponent implements OnInit {
- id: string;
- article: any = {};
- constructor(private articleService: ArticleService,
- private router: Router,
- private activatedRoute: ActivatedRoute) { }
- ngOnInit() {
- this.activatedRoute.params.subscribe(params => this.id = params.id);
- this.articleService.getOneArticle(this.id).subscribe(article => {
- console.log(article);
- this.article = article;
- });
- }
- editArticle(id) {
- this.router.navigate([`/articles/edit/${id}`]);
- }
- deleteArticle(id) {
- if (confirm('You are about to permanently remove this article. Continue?')) {
- this.articleService.deleteArticle(id).subscribe(() => {
- this.router.navigate(['/articles']);
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement