I start in the Angular CLI, I used the login api: http: //localhost/appointjobs/index.php/admin_api/index 'using http.post, but, I did not receive the server side data (codeigniter / php) during installation 'content-type:application/json'. Below is the code that I used in the login services, as well as receiving messages after use 'application/x-www-form-urlencoded'instead of "application / json".
DataService.ts file:
import { BadInputError } from './../common/bad-input-error';
import { error } from 'selenium-webdriver';
import { AppError } from './../common/app-error';
import { Observable } from 'rxjs/Observable';
import { Http, ResponseOptionsArgs,RequestOptionsArgs,Headers,RequestOptions } from '@angular/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/throw';
import { NotFoundError } from '../common/not-found-error';
import { Response } from '@angular/http/src/static_response';
import { HttpHeaders } from '@angular/common/http';
@Injectable()
export class DataService {
constructor(private http:Http) {
}
getWhere(url,resource){
let headers= new Headers();
headers.append('Accept','text/plain');
headers.append('content-type','application/json');
let option= new RequestOptions({headers:headers});
return this.http.post(url,JSON.stringify(resource),option)
.map(response=>response.json())
.catch(this.handleError);
}
}
File AuthService.ts:
import { DataService } from './data.service';
import { Injectable } from '@angular/core';
@Injectable()
export class AuthService{
private url = 'http://localhost/appointjobs/index.php/admin_api/index';
constructor(private dataService:DataService) {
}
signIn(params:HTMLInputElement){
this.dataService.getWhere(this.url,params)
.subscribe(response=>{
console.log(response);
});
}
}
source
share