Angular 类型脚本错误TS2554:应为0个参数,但得到1个。在离子应用中

Angular 类型脚本错误TS2554:应为0个参数,但得到1个。在离子应用中,angular,typescript,ionic-framework,Angular,Typescript,Ionic Framework,大家好。我在我的项目中遇到了这样的问题,类型为脚本错误TS2554:应为0个参数,但得到1个。此错误使我无法为自定义输入弹出窗口创建“选择其他选项”。在这个论坛上,我发布了typescript代码和typescript代码的错误部分。 打字脚本代码 import { Validators, FormBuilder, FormGroup, FormControl } from '@angular/forms'; import { AlertController } from '@ionic

大家好。我在我的项目中遇到了这样的问题,类型为脚本错误TS2554:应为0个参数,但得到1个。此错误使我无法为自定义输入弹出窗口创建“选择其他选项”。在这个论坛上,我发布了typescript代码和typescript代码的错误部分。

打字脚本代码

 import { Validators, FormBuilder, FormGroup, FormControl } from '@angular/forms';
  import { AlertController } from '@ionic/angular';

  constructor(
    public formBuilder: FormBuilder,
    public alertController: AlertController
  ) { }

      ngOnInit() {
      this.religions = [
          "Islam",
          "Buddha",
          "Hinduism",
          "Christian",
          "Sikhism",
          "Taiosm",
          "Other"
        ];
        
        this.currentReligionValue = "Islam";
      
        this.validations_form = this.formBuilder.group({
        religion: new FormControl(this.currentReligionValue, Validators.required),
    });
    }

      validation_messages = {
    'religion': [
      { type: 'required', message: 'Religion is required to select' },
  };

  //When have other values
  selectChanged(selected) {
    if (selected === 'Other') {
      this.inputValue();
    } else {
      this.currentvalue = selected;
    };
  };
类型脚本中的错误部分

async inputValue() {
        const inputAlert = await this.alertController.create({
          header: 'Enter your custom color:',
          inputs: [ { type: 'text', placeholder: 'type in' } ],
          buttons: [ { text: 'Cancel' }, { text: 'Ok' } ]
        });
      inputAlert.onDidDismiss((data) => { //<-- The error part is starting here
          let customName: string = data.data.values[0];
          if (customName) {
            let indexFound = this.religions.findIndex(religion => religion === customName)
            if (indexFound === -1) {
              this.religions.push(customName);
              this.currentReligionValue = customName;
            } else {
              this.currentReligionValue = this.religions[indexFound];
            };
          };      
        }).catch(err=>console.log(err));
        await inputAlert.present();
      };
async inputValue(){
const inputAlert=等待this.alertController.create({
标题:“输入自定义颜色:”,
输入:[{type:'text',占位符:'type in'}],
按钮:[{text:'Cancel'},{text:'Ok'}]
});
inputAlert.OnDidDisclesh((数据)=>{//Religation==customName)
如果(indexFound==-1){
这个.宗教.推送(customName);
this.currentReligionValue=customName;
}否则{
this.currentReligionValue=this.Relights[indexFound];
};
};      
}).catch(err=>console.log(err));
等待inputAlert.present();
};
根据,方法
ondiddisclesh()
不接受任何参数。
它返回一个
OverlayEventDetail
Promise
,在警报确实解除时解析

下面的代码应该可以正常工作

const-inputAlert=wait this.alertController.create({…});
inputAlert.ondiddisclesh()
.然后((事件:OverlayEventDetail)=>事件数据…)
.catch(console.log);

如果您想在访问回调中的数据时自动完成,可以键入方法。

Hi,Reqven,您的答案对我非常有用。非常感谢。