I use the plug-in ng2-restangular.
I made the plug-in setting to export function when importing the restangular module from “app.module.ts”.
I am trying to use the service I made by implanting it into the export function, but it doesn’t work.
Can you either let me know the way to import services into export function or let me know how to use LoadingController?
=========================== app.module.ts ===========================
…
import {AlertService} from “…/services/alert.service”;
import {RestangularModule} from “ng2-restangular”;
…
@NgModule({
declarations: [
MyApp,
…
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
RestangularModule.forRoot(RestangularConfigFactory),
…
],
bootstrap: [IonicApp],
entryComponents: [
…
],
providers: [
…
AlertService
],
})
export function RestangularConfigFactory (RestangularProvider) {
…
RestangularProvider.addFullRequestInterceptor((element, operation, path, url, headers, params)=> {
_/**_
_ Use in AlertService method _
_ **/_
return {
// params: Object.assign({}, params, {sort:"name"}),
params: Object.assign({}, params),
headers: headers,
element: element
}
});
…
}
=======================================================================
=========================== alert.service.ts (AlertService) ======================
/**
*
- Created by COM on 2017-08-07.
- */
import {Injectable} from “@angular/core”;
import {AlertController, LoadingController, ToastController} from “ionic-angular”;
@Injectable()
export class AlertService{
private toast: any;
private alert: any;
private loading: any;
constructor(
private toastCtrl: ToastController,
private alertCtrl: AlertController,
private loadingCtrl: LoadingController ) {
console.log("AlertService Init");
}
// Toast 창 띄우기
alertToast = (message: string, time: number)=> {
let options:{[k: string]: any} = {};
if (time == undefined) { time = 2000; }
options.message = message;
options.duration = time;
options.position = 'top';
this.toast = this.toastCtrl.create(options).present();
}
// Loading
showLoading = (message: string, time: number) => {
let options:{[k: string]: any} = {};
options.content = message;
this.loading = this.loadingCtrl.create(options);
this.loading.present();
if (time > 0) {
setTimeout(
()=> { this.loading.dismiss(); }, time);
}
}
hideLoading = () => {
if (this.loading != undefined){
this.loading.dismiss();
}
}