Ionic 2 中的静态获取参数()目的是什么? [英] What is static get parameters() purpose in Ionic 2?

查看:20
本文介绍了Ionic 2 中的静态获取参数()目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现最新的 Ionic 2 Beta 中有一个新结构.
看起来像这样:

I found out that there is a new construction in latest Ionic 2 Beta.
It looks like that:

export class ListPage {    
static get parameters() {
        return [[NavController], [NavParams]];
      }
...

谁能给我解释一下或提供某种教程的链接或此方法用途的详细说明?以及它是如何与页面构造函数、注入和模块联系起来的?

Could anyone please explain me or give a link to some kind of tutorial or detailed explanation of the purpose of this method? And how it is connected with Page constructor, injection and modules?

推荐答案

使用静态 getter 参数,您可以为组件的构造函数指定注入

With static getter for parameters you specify injections for your component's constructor

它为 Angular 提供了关于它应该在构造函数中注入的东西的元数据

It provide Angular with metadata about things it should inject in the constructor

这里提供了关于NavControllerNavParams

现在在构造函数中你将拥有这些

Now in constructor you will have these as

 constructor(nav, navParams) {....}

来自这个页面

静态获取参数()到底是什么?

What the heck is that static get parameters()?

Angular2 是用 TypeScript 编写的,通常依赖于类型来知道将什么样的对象注入到类构造函数中,作为其依赖注入框架的一部分.由于这些示例是在 JavaScript 而不是 TypeScript 中,我们需要一种方法来告诉 Angular 应该注入什么类型"的对象,而无需实际使用类型.我们这样做的方法是使用静态 getter 参数,将这种类型信息附加到类中.

Angular2 is written in TypeScript, and normally depends on types to know what kind of objects to inject into class constructors as part of its dependency injection framework. Since these examples are in JavaScript and not TypeScript, we need a way to tell Angular what "types" of objects should be injected, without actually using types. The way we do this is with the static getter parameters which attaches this type information to the class.

这篇关于Ionic 2 中的静态获取参数()目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆