Skip to content

Instantly share code, notes, and snippets.

@rakeshkumar125
Created August 23, 2018 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rakeshkumar125/02ad1a4834a992be893dae9d299fda57 to your computer and use it in GitHub Desktop.
Save rakeshkumar125/02ad1a4834a992be893dae9d299fda57 to your computer and use it in GitHub Desktop.
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