我的应用程序是使用Ionic4和Range8构建的。它为alertcontroller和toastcontroller创建了一个服务,这两个服务都由调用构造函数使用,并应用于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
) {
// …发布于 2019-10-18 13:22:32
您不需要将函数作为服务中的参数发送。如果您真的想用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();
}
}我不知道你从哪里得到你的副词,所以那部分由你决定。
https://stackoverflow.com/questions/58448517
复制相似问题