0.0.7 • Published 5 years ago

angular-news-api v0.0.7

Weekly downloads
24
License
-
Repository
github
Last release
5 years ago

NewsAPI - An Angular Interface for NewsAPI

This Library provides everything you need to use the NewsAPI from you Angular app the way it should be: using Observables, Types and Dependency Injection.

Installing in your project

npm install --save angular-news-api

Using in your Angular application

Import the AppRoutingModule into your app module and configure your API Key:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { NgnewsModule } from 'angular-news-api';
import { NewsApiKeyConfig } from 'angular-news-api';

const newsApiConfig: NewsApiKeyConfig = {
  key: 'API_KEY_FROM_NEWS_API'
};

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgnewsModule.forRoot(newsApiConfig)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Now you can use all the endpoints of the API:

constructor(private newsApiService: NewsApiService) {}

topHeadlines() {
 this.newsApiService.topHeadlines({
       sources: 'bbc-news,the-verge'
     }).subscribe(data => console.log(data));
}

everything() {
 this.newsApiService.everything({
       q: 'trump'
     }).subscribe(data => console.log(data));
}

sources() {
 this.newsApiService.sources({
       country: 'us'
     }).subscribe(data => console.log(data));
}

Check the official documentation for more info about the options in each endpoint.

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago