Advertisement
Shell_Casing

articles Component class

Dec 12th, 2018
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import { Component, 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 {
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement