Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Injectable()
- export class ApiService {
- public serviceName: string = "";
- urlRoot: string = "http://localhost:3000/api/v1/";
- constructor(private http: Http){
- }
- get(urlApi?: string, params?: Array<object>): Observable<any>{
- return this.http.get(this.urlRoot+this.serviceName, {headers: this.getHeaders()})
- .map((res:Response) => res.json())
- }
- @Injectable()
- export class NewsService extends ApiService{
- public serviceName: string = "news";
- private id: string;
- }
- export class NewsComponent implements OnInit {
- private news: News[];
- constructor(private newsService: NewsService) { }
- ngOnInit() {
- this.newsService.get().subscribe(
- result => this.news = result,
- error => console.log("Error: ", error)
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement