财产' x'是私人的,只能在课堂上访问' y'

时间:2016-08-08 20:28:31

标签: javascript angular typescript ionic-framework ionic2

我有这段代码:

   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

2 个答案:

答案 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();
  }
}