- 新建一个类,命名为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文件中添加入下代码:
3.使用封装的服务,比如在mian.ts中使用,具体代码入下: