2

I've import Alert Component in my ionic 2 project like this :

import {Alert } from 'ionic-angular';

Usage:

let alert = this.alert.create({
    title: 'New Friend!',
    subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
      buttons: ['OK']
    });
alert.present();

But my error is : Property create does not exist on type Alert.

Ionic Info :

Cordova CLI: 6.3.0
Gulp version:  CLI version 1.2.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.37
Ionic App Lib Version: 2.0.0-beta.20
ios-deploy version: 1.8.6 
ios-sim version: 5.0.8 
OS: Mac OS X El Capitan
Node Version: v5.12.0
Xcode version: Xcode 7.3 Build version 7D175 

how can i solve it ?

Mahmoud Ismail
  • 1,617
  • 4
  • 27
  • 51

1 Answers1

5

It seems to me that you are using pieces of new pattern for creating alerts, but you have Ionic Framework 10, where things are done a bit differently.

You should inject AlertController into constructor. Also, when importing Alert, it has new name - AlertController.

More on new way of creating overlays (incluiding alerts) at official Ionic 2 blog.

edit: If you want to update to Beta 11, just run:

npm install --save --save-exact ionic-angular @angular/common@2.0.0-rc.4 @angular/compiler@2.0.0-rc.4 @angular/core@2.0.0-rc.4 @angular/http@2.0.0-rc.4 @angular/platform-browser@2.0.0-rc.4 @angular/platform-browser-dynamic@2.0.0-rc.4 @angular/forms rxjs@5.0.0-beta.6 zone.js@0.6.12

I had troubles updating, got npm WARN unmet dependency, so I did reinstall npm in my Ionic directory:

  1. remove node_modules using rm -rf node_modules/
  2. run npm cache clean
  3. run mentioned npm install command again

You also need to fix other changes in Beta 11, as mentioned at Beta 11 changelog. More on failed npm install due to unmet dependencies at SO.

Community
  • 1
  • 1
Kuba Chour
  • 549
  • 1
  • 5
  • 16
  • 1
    And for the beta 10 implementation you call `create` on the Alert class... `let alert = Alert.create({ options })` and present it with the NavController `this.navCtrl.present(alert);` – Will.Harris Aug 17 '16 at 08:58
  • ok thanks for your response but how can i update the Ionic 2 in the existing project? – Mahmoud Ismail Aug 17 '16 at 09:02
  • @mahmoudismail Beta 11 installation added in answer – Kuba Chour Aug 17 '16 at 09:56
  • 1
    @mahmoudismail: you can change it in package.json on following line: "ionic-angular": "^2.0.0-beta.11" and then delete node_modules and run "npm install". And then don't forget look on steps to upgrade to beta 11: https://github.com/driftyco/ionic/blob/master/CHANGELOG.md#steps-to-upgrade-to-beta-11 – J V Aug 17 '16 at 11:16
  • "inject AlertController into constructor" was the issue, Thank you – Meir Feb 19 '18 at 09:06