Created
August 23, 2018 01:47
-
-
Save rakeshkumar125/02ad1a4834a992be893dae9d299fda57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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