Advertisement
Shell_Casing

list component

Dec 13th, 2018
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Component, OnDestroy, OnInit} from '@angular/core';
  2.  
  3. import { ArticleInterface } from '../../article-interface';
  4. import { ArticleService } from '../../article.service';
  5.  
  6. @Component({
  7.   selector: 'app-list',
  8.   templateUrl: './list.component.html',
  9.   styleUrls: ['./list.component.css']
  10. })
  11. export class ListComponent implements OnInit, OnDestroy {
  12.  
  13.   filteredArticles: ArticleInterface[];
  14.  
  15.   constructor(private articleService: ArticleService) { }
  16.  
  17.   ngOnInit() {
  18.     this.getArticles();
  19.   }
  20.  
  21.   getArticles() {
  22.     this.articleService.getAllArticles().subscribe((articles: ArticleInterface[]) => {
  23.       console.log(articles);
  24.       this.articleService.articles = articles;
  25.       this.articleService.articles = this.articleService.articles.reverse();
  26.       this.filteredArticles = this.articleService.articles;
  27.     });
  28.   }
  29.  
  30.   filterArticles(query) {
  31.     this.filteredArticles = query ?
  32.       this.articleService.articles.filter(article => article.title.toLowerCase().includes(query.toLowerCase())) :
  33.       this.articleService.articles;
  34.   }
  35.  
  36.   ngOnDestroy() {
  37.  
  38.   }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement