我有这段代码:
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
}
当我运行ionicserve
时,一切都显示正确,但是当我单击调用findItems()
方法的按钮时,我收到此错误:
Error TS2341: Property 'create' is private and only accessible within class 'Loading
如果我这样做,则会出现类似的错误:
let alert = Alert.create({
title: 'Hello!',
});
在这种情况下,我的终端中会显示以下消息:错误 TS2341:属性“create”是私有(private)的,只能在“Alert”类中访问。
我正在使用 Ionic2 版本 2.0.0-beta.36
最佳答案
编辑:这仅适用于 beta 11 及更高版本
这是因为 create
是 private Loading
类的函数,因此不能在 Loading
类之外调用。
code example Ionic 的文档显示了一个 LoadingController 类,用于使用所需选项实例化 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
}
关于javascript - 属性 'x' 是私有(private)的,只能在类 'y' 内访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38837964/