I used Http Restful API at Angular2, but appear the following warning message.
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Please tell me how to do that.
http_restful_service.ts
import { Injectable } from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class HTTPRestfulService { constructor(private _http: Http) {} getAllProjectName() { var headers = new Headers(); headers.append('Content-Type','charset=uft-8'); return this._http.get('http://localhost/api/database/', {headers: headers}) .map(res => res.json()); }
}
backstage_view.component.ts
import { Component, OnInit } from '@angular/core';
import { HTTPRestfulService } from './../../../service/http_restful_service';
@Component({ moduleId: module.id, selector: 'backstage_view', templateUrl: './backstage_view.component.html', styleUrls: ['./backstage_view.component.css']
})
export class BackstageViewComponent implements OnInit { allProjects: string; constructor(private _restfulapi: HTTPRestfulService) {} ngOnInit() { this._restfulapi.getAllProjectName() .subscribe( data => this.allProjects = data, error => console.log(error), ); }
}