IONIC Angular8应用程序生产构建生成错误

时间:2019-10-18 10:02:20

标签: jquery ionic4 angular8

我的应用程序是使用Ionic4和Angular 8构建的。它为alertcontrollertoastcontroller创建了一个服务,并且都由调用构造函数使用,并应用于 Firebase 配置中,但是当我构建时,出现以下错误。

有人知道来源吗?

ERROR: Can't resolve all parameters for GeneralFunctionService in 
    /home/dhwani/IONIC/demo/src/app/service/general-function.service.ts:
    ([object Object], [object Object], ?). 

GeneralFunctionService:

import { Injectable } from '@angular/core'; 
import { ToastController, AlertController, NavController } from '@ionic/angular';

@Injectable({ providedIn: 'root' }) 
export class GeneralFunctionService { 
 params: any;

 constructor(
  public alertCtrl: AlertController, 
  public toastCtrl: ToastController, 
  params: string 
 ) {
 // …

1 个答案:

答案 0 :(得分:0)

您不需要在服务中将函数作为参数发送。如果您真的想使用if语句执行此操作,则应在组件内执行此操作。

这样您就可以保持服务的良好和整洁:

import {Injectable} from '@angular/core';
import {ToastController,AlertController,NavController} from '@ionic/angular';

@Injectable({
    providedIn: 'root'
})

export class GeneralFunctionService {
    constructor(
        public alertCtrl: AlertController,
        public toastCtrl: ToastController,
    ) {}

    async showErrorMsg(toastCtrl, msg) {
        let toast = await toastCtrl.create({
            message: msg,
            duration: 2000,
            position: 'top'
        });
        await toast.present();

        window.location.reload();
    }

    async showAlertError() {
        let alert = await this.alertCtrl.create({
            message: 'Login Sucessful',
            buttons: [{
                text: 'OK',
                handler: () => {
                    window.location.reload();
                }
            }, ]
        });
        await alert.present();
    }
}

然后,您应该在组件中导入服务并使用它。

contructor(generalFunctionServ: GeneralFunctionService) {}

showMessage(param){
   if (param === 'showErrorMsg') { 
    this.generalFuncServ.showErrorMsg();
   } else if (param === 'showAlertError') { 
    this.generalFuncServ.showAlertError();
   }
}

我不确定您是从哪里获得参数的,所以这部分取决于您。