我有这段代码:
import { Component } from '@angular/core';
import { NavController, Loading, Alert } from 'ionic-angular';
@Component({
templateUrl: 'build/pages/search/search.html',
})
export class SearchPage {
constructor (....)
{
// code here
}
findItems()
{
let loading = Loading.create({
content: "Finding items..."
});
this.nav.present(loading);
// other stuff here
}
当我运行ionic serve
时,所有内容都显示正确,但当我点击调用findItems()
方法的按钮时,我收到此错误:
Error TS2341: Property 'create' is private and only accessible within class 'Loading
如果我这样做,会出现类似的错误:
let alert = Alert.create({
title: 'Hello!',
});
在这种情况下,在我的终端中会显示以下消息:Error TS2341: Property 'create' is private and only accessible within class 'Alert'.
我正在使用Ionic2版本2.0.0-beta.36
答案 0 :(得分:2)
编辑:这仅适用于beta 11及更高版本
这是因为Loading
是类Loading
的{{3}}函数,因此无法在LoadingController
类之外调用。
Ionic的文档中的private显示了一个import { LoadingController } from 'ionic-angular';
//...
constructor(private loadingController: LoadingController) {
}
findItems() {
let loading = this.loadingController.create({
content: "Finding items..."
duration: 3000
});
loading.present();
// other stuff here
}
类,用于使用所需选项实例化Loading对象。我会从那里开始。
extent
答案 1 :(得分:0)
看起来Alerts的语法已经改变了。这是新语法:
import { AlertController } from 'ionic-angular';
export class MyPage {
constructor(private alertController: AlertController){
}
showAlert() {
let alert = this.alertController.create({
title: 'New Friend!',
subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
buttons: ['OK']
});
alert.present();
}
}