Advertisement
Shell_Casing

ngOnInit

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