Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { Injectable, EventEmitter, Output } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Response } from "@angular/http";
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';
@Injectable()
export class AppService{
isLoggedin:boolean;
@Output() getLoggedInName = new EventEmitter();
constructor(private _http: HttpClient){
}
//function get categories from database
getCategories(){
return this._http.get("http://localhost/api/categories")
.map(res=>{return res;});
}
//function get categories from database
getposts(params){
return this._http.get("http://localhost/api/posts")
.map(res=>{return res;});
}
}
//=========== how to call in controller
/*import { AppService } from '../shared/app.service';
allPosts;
constructor(private service:AppService) { }
this.service.getposts().subscribe(res=>{ this.allPosts= res; });*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.