App.modules.ts也需要导入
import { HttpModule } from '@angular/http';
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp)
],
调用页面导入:
import { Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
constructor(...........,public http: Http ) {
}
调用方式:
this.http.request('http://localhost:8088/RestServer/worker/loadById/'+usercode.value)
.toPromise() .then(res =>{
alert(JSON.stringify(res.json(), null, 4));
) .catch(err => { alert(err); });