Property 'present' does not exist on type '(message?: any) => void'


Hi everyone,

I’m trying to display an alert prompt. I imported AlertController from ionic-angular and registered alertCtrl in my constructor.

But I’m getting this error when trying to compile my program.

Property ‘present’ does not exist on type ‘(message?: any) => void’.

I copied/pasted the official code from the ionic documentation so I can’t figure out what I’m doing wrong.

Here’s my code:

import { Alert, AlertController } from 'ionic-angular';

    platform: Platform,
    private fb: Facebook,
    private device: Device,
    private storage: Storage,
    private navCtrl: NavController,
    private alertCtrl: AlertController,
    private userService: NmUserService,
    private deviceService: NmDeviceService
  ) { }

presentPrompt(flag: boolean) {
    if (flag == true) {
      let alert = this.alertCtrl.create({
        title: 'Pseudo déjà utilisé',
        inputs: [
            name: 'username',
            placeholder: 'Ce pseudo est déjà utilisé, choisissez-en un autre.'
        buttons: [
            text: 'Cancel',
            role: 'cancel',
            handler: data => {
              console.log('Cancel clicked');
            text: 'Confirmer',
            handler: data => {
              this.token.user.username = data.username;
              this.userService.update(this.token.user, this.token).subscribe(
                (result) => {
                (error) => {
  alert.present(); // The error is here.

Thanks to anyone that will take the time to read and/or help me.


The alert that you are apparently attempting to access is inside the scope of the if (flag) block, but your access attempt is outside it. Move the present() line up above the closing } that is currently above it.


Thanks, I didn’t know the difference between let and var :slight_smile: