Skip to content

Latest commit

 

History

History
102 lines (71 loc) · 4.72 KB

README.md

File metadata and controls

102 lines (71 loc) · 4.72 KB

⚡ Angular News App

  • Gets API news data and displays it in a format suitable for viewing on a phone.
  • Displays a left hand side navigation bar that allows the user to select a news channel. A single column displays news articles from this news channel.
  • The News API service from newsapi is used to generate the articles. It now only works on localhost. It will not work when deployed due to CORS errors (error 406) which means they want you to pay a subscription to fully access the API.
  • Code from article by Rashid Sakara - see 👏 Inspiration below
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

📄 Table of contents

📚 General info

  • Uses the model-view-viewmodel (MVVM) of Angular to bind the remote data that is stored in objects in the application template. The component plays the part of the controller/viewmodel. The template represents the view.
  • Very basic app to show news, does not use reactive programming best practices - specified function return types, typescript models, etc....

📷 Screenshots

Example screenshot.

📶 Technologies

💾 Setup

  • Install dependencies using npm i
  • Get yourself a free API key from www.newsapi.org and add it to news-api.service.ts
  • Run ng serve for a dev server. Navigate to http://localhost:4200/. The app does automatically reload if you change any of the source files.

💻 Code Examples

  • news-api.service.ts to get API news data using Angular httpClient module.
import { Injectable } from '@angular/core';
import { HttpClient  } from '@angular/common/http';


@Injectable({
  providedIn: 'root'
})
export class NewsApiService {

  api_key = 'YOUR API KEY';

  constructor(private http: HttpClient) { }
  initSources() {
     return this.http.get('https://newsapi.org/v2/sources?language=en&apiKey=' + this.api_key);
  }
  initArticles() {
   return this.http.get('https://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey=' + this.api_key);
  }
  getArticlesByID(source: String) {
   return this.http.get('https://newsapi.org/v2/top-headlines?sources=' + source + '&apiKey=' + this.api_key);
  }
}

🆒 Features

  • Angular HttpClient module used to communicate with back-end services via the XMLHttpRequest browser interface.
  • Updated may 2021

📋 Status & To-Do List

  • Status: Working.
  • To-Do: nothing. I have done other news apps using the same API.

👏 Inspiration

📁 License

  • This project is licensed under the terms of the MIT license.

✉️ Contact