属性 'x' 是私有的,只能在 class 'y' 内访问
Property 'x' is private and only accessible within class 'y'
我有这段代码:
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
编辑:这仅适用于 beta 11 及更高版本
这是因为 create
是 class Loading
的 private 函数,因此无法在 Loading
class 之外调用].
Ionic 文档中的 code example 显示了 LoadingController
class 用于实例化具有所需选项的 Loading 对象。我将从那里开始。
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
}
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();
}
}
我有这段代码:
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
编辑:这仅适用于 beta 11 及更高版本
这是因为 create
是 class Loading
的 private 函数,因此无法在 Loading
class 之外调用].
Ionic 文档中的 code example 显示了 LoadingController
class 用于实例化具有所需选项的 Loading 对象。我将从那里开始。
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
}
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();
}
}