- 新建一個類粉渠,命名為app.service.ts,位于src/app/目錄下旨袒,具體代碼如下:
import { LoadingController, AlertController, ToastController } from 'ionic-angular';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class AppGlobal {
}
@Injectable()
export class AppService {
constructor(public http: Http, ) { }
}
2.在app.module.ts文件中添加入下代碼:
image.png
3.使用封裝的服務(wù)瓣铣,比如在mian.ts中使用,具體代碼入下:
image.png