属性'x'是私有的,只能在'y'类中访问 [英] Property 'x' is private and only accessible within class 'y'
问题描述
我有这段代码:
从'@ angular / core'导入{Component};来自'ionic-angular'的
import {NavController,Loading,Alert};
@Component({
templateUrl:'build / pages / search / search.html',
})
导出类SearchPage {
构造函数(....)
{
//代码在这里
}
findItems()
{
let loading = Loading.create({
content:查找项目......
});
this.nav.present(loading);
//这里的其他东西
}
当我运行 ionic serve
一切都正确显示但当我点击一个调用 findItems()
方法的按钮时,我收到此错误:
错误TS2341:属性'create'是私有的,只能在类'Loading
$ p $中访问p>
如果我这样做,则会出现类似的错误:
let alert = Alert。 create({
title:'Hello!',
});
在这种情况下,在我的终端中出现以下消息:
错误TS2341:属性' create'是私有的,只能在课堂'Alert'中访问。
我正在使用Ionic2版本2.0.0-beta.36
解决方案编辑:这仅适用于beta 11及更高版本
这是因为
create
是 private 函数正在加载
,因此无法在加载
类。
代码示例来自Ionic的文档显示了一个
LoadingController
类,用于使用所需选项实例化Loading对象。我会从那里开始。从'ionic-angular'导入{LoadingController};
// ...
构造函数(private loadingController:LoadingController){
}
findItems(){
let loading = this.loadingController.create({
content:Finding items ...
duration:3000
});
loading.present();
//这里的其他东西
}
I have this piece of code:
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 }
When I run
ionic serve
everything shows correctly but when I click a button which callsfindItems()
method I get this error:Error TS2341: Property 'create' is private and only accessible within class 'Loading
An analogous errors appears if I do:
let alert = Alert.create({ title: 'Hello!', });
In this case in my terminal appears following message:
Error TS2341: Property 'create' is private and only accessible within class 'Alert'.
I'm working with Ionic2 version 2.0.0-beta.36
解决方案EDIT: This only applies to beta 11 and higher
This is because
create
is a private function of the classLoading
, and therefore not callable outside of theLoading
class.The code example from Ionic's documentation shows a
LoadingController
class used to instantiate the Loading object with the desired options. I would start there.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 }
这篇关于属性'x'是私有的,只能在'y'类中访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!