Angular/Ionic 2 - 什么是提供者,`static get parameters()` 有什么作用?

Angular/Ionic 2 - what is a provider and what does `static get parameters()` do?

我正在学习 Angular 2(使用 Ionic 2)- 我无法从 Angular 1.

中了解两个概念

我有一个 class 如下:

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);
        });
    }
}

什么是提供商,它的作用是什么do/what它的目的是什么?

以下代码的作用:

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

因为你使用的是 ES6,所以你没有参数类型。以下是不可能的(仅 TypeScript):

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

使用静态 getter 您将配置要提供给构造函数的参数类型。 Angular2 依赖注入将利用它来了解使用哪些提供者来注入构造函数的参数。它读取 parameters 属性 的内容为 class...

使用 getter 定义此 "static" 属性 的值。