Angular/Ionic 2 - 什么是提供者以及“static getparameters()”的作用是什么?

2023-12-28

我正在学习 Angular 2(使用 Ionic 2)——有两个概念无法与 Angular 1 联系起来。

我有一堂课如下:

import {App, Platform} from 'ionic-angular';
import {RegisterPage} from './pages/register/register';


@App({
    templateUrl: 'build/index.html',
    config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
    static get parameters() {
        return [[Platform]];
    }

    constructor(platform) {
        this.rootPage = RegisterPage;

        platform.ready().then(() => {
            // The platform is now ready. Note: if this callback fails to fire, follow
            // the Troubleshooting guide for a number of possible solutions:
            //
            // Okay, so the platform is ready and our plugins are available.
            // Here you can do any higher level native things you might need.
            //
            // First, let's hide the keyboard accessory bar (only works natively) since
            // that's a better default:
            //
            // Keyboard.setAccessoryBarVisible(false);
            //
            // For example, we might change the StatusBar color. This one below is
            // good for dark backgrounds and light text:
            StatusBar.setStyle(StatusBar.LIGHT_CONTENT);
        });
    }
}

什么是提供商?它的作用是什么/其目的是什么?

下面的代码做了什么:

static get parameters() {
    return [[Platform]];
}

由于您使用 ES6,因此没有参数类型。以下是不可能的(仅限 TypeScript):

export class MyApp {
  constructor(platform:Platform) {
  }
}

使用静态 getter,您将配置提供给构造函数的参数类型。 Angular2 依赖注入将利用它来知道使用哪些提供者来注入构造函数的参数。它读取了内容parameters班级的财产...

使用 getter 可以定义这个“静态”属性的值。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular/Ionic 2 - 什么是提供者以及“static getparameters()”的作用是什么? 的相关文章

随机推荐