Advertisement
Shell_Casing

Untitled

Jan 22nd, 2019
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { NewsAPIService } from '../news-api.service';
  3.  
  4. @Component({
  5. selector: 'app-home',
  6. templateUrl: './home.component.html',
  7. styleUrls: ['./home.component.css']
  8. })
  9. export class HomeComponent implements OnInit {
  10.  
  11. headlinesArray: Array<any>;
  12. sourcesArray: Array<any>;
  13.  
  14. constructor(private newsApi: NewsAPIService) { }
  15.  
  16. ngOnInit() {
  17. // get sources
  18. this.getSources();
  19.  
  20. // get headlines
  21. this.getHeadlines();
  22. }
  23.  
  24. getSources() {
  25. this.newsApi.initializeSources().subscribe(data => {
  26. this.sourcesArray = data['sources'];
  27. });
  28. }
  29.  
  30. getHeadlines() {
  31. this.newsApi.initializeHeadlines().subscribe(data => {
  32. this.headlinesArray = data['articles'];
  33. });
  34. }
  35.  
  36. searchArticles(sourceId) {
  37. console.log(sourceId);
  38. this.newsApi.getArticlesByID(sourceId).subscribe(data => {
  39. this.headlinesArray = data['articles'];
  40. });
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement