Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- import { ArticleInterface } from '../../article-interface';
- import { ArticleService } from '../../article.service';
- @Component({
- selector: 'app-list',
- templateUrl: './list.component.html',
- styleUrls: ['./list.component.css']
- })
- export class ListComponent implements OnInit {
- articles: ArticleInterface[];
- constructor(private articleService: ArticleService, private router: Router) { }
- ngOnInit() {
- this.getArticles();
- }
- 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.ngOnInit());
- }
- }
- getArticles() {
- this.articleService.getAllArticles().subscribe((articles: ArticleInterface[]) => {
- console.log(articles);
- this.articles = articles;
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement