Advertisement
DeepCode00

Untitled

May 11th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Injectable()
  2. export class ApiService {
  3.     public serviceName: string = "";
  4.     urlRoot: string = "http://localhost:3000/api/v1/";
  5.  
  6.     constructor(private http: Http){
  7.     }
  8.  
  9.     get(urlApi?: string, params?: Array<object>): Observable<any>{
  10.         return this.http.get(this.urlRoot+this.serviceName, {headers: this.getHeaders()})
  11.                         .map((res:Response) => res.json())
  12.     }
  13.  
  14. @Injectable()
  15. export class NewsService extends ApiService{
  16.     public serviceName: string = "news";
  17.     private id: string;
  18.  
  19. }
  20.  
  21. export class NewsComponent implements OnInit {
  22.   private news: News[];
  23.  
  24.   constructor(private newsService: NewsService) { }
  25.  
  26.   ngOnInit() {
  27.     this.newsService.get().subscribe(
  28.       result => this.news = result,
  29.       error => console.log("Error: ", error)
  30.     );
  31.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement