4

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?

1 Answer 1

9

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

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

Here it provides netadata about NavController and NavParams

Now in constructor you will have these as

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

From this page

What the heck is that static get parameters()?

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! But maybe you know how it is works under the hood?
I have updated my answer to explain more, you have to read about reflects,annotatation an more to understand underhood workings, i dont know much of that either :)
Thanks! I saw this tutorial, and actually was exactly on the same page you referenced, but haven't scroll to bottom yet to see this explanation! Classical RTFM :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.