类型为Alert时,不存在Ionic 2警报组件属性创建

mah*_*ail 2 alert components ionic2

Alert Component在我的ionic 2项目中导入如下:

import {Alert } from 'ionic-angular';
Run Code Online (Sandbox Code Playgroud)

用法:

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

但我的错误是: Property create does not exist on type Alert.

离子信息:

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 
Run Code Online (Sandbox Code Playgroud)

我怎么解决呢?

Kub*_*our 5

在我看来,您正在使用新模式的片段来创建警报,但您有Ionic Framework 10,其中的事情有点不同.

您应该将AlertController注入构造函数.此外,导入Alert时,它具有新名称 - AlertController.

更多关于在官方Ionic 2博客创建叠加(包括警报)的新方法.

编辑:如果您要更新到Beta 11,只需运行:

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
Run Code Online (Sandbox Code Playgroud)

我有麻烦更新,获得npm WARN未满足的依赖,所以我在我的Ionic目录中重新安装了npm:

  1. 使用rm -rf node_modules /删除node_modules
  2. 运行npm缓存清理
  3. 再次运行npm install命令

您还需要修复Beta 11中的其他更改,如Beta 11更新日志中所述.更多关于npm安装失败的原因是由于 SO的未满足依赖性.