1、ionic get 请求配置
1)要想使用 HttpClient,就要先导入 Angular 的 HttpClientModule。在根模块 AppModule 中导入它。
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
// import HttpClientModule after BrowserModule.
HttpClientModule,
],
declarations: [ AppComponent,],
bootstrap: [ AppComponent ]
})
export class AppModule {}
2)再把 HttpClient 注入到需要使用http请求的页面,就像下面的 home.ts中这样。
import { HttpClient } from '@angular/common/http';
import { Component,Injectable } from '@angular/core';
@Injectable()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {constructor(public navCtrl: NavController,private http: HttpClient) {
}
get请求与get拼接
configUrl = 'http://office.techrare.com:5681/deskapi/index.php/welcome/alltable?is_pay=1';
gethttp() {
return this.http.get(this.configUrl).subscribe((data: any) => {
console.log(data);
});
}
}