Why do I need to write static get parameters()

I been trying to migrate my Ionic 1 application to Ionic 2 and have been encountering alot of new terms and problems.

I do not really understand the need for get parameters() and when and what variables to return in that function.

For example(To Navigate):

 static get parameters() {
    return [[NavController]];

Previously in an older ionic build(I’m not sure which version I was developing upon), I can navigate to pages without this function. In the latest ionic 2 build(2.0.0-beta.25) , without this get parameters() function, it just wont navigate to the next targeted page , but there are no errors.

I’m aware of a existing post:
Angular/Ionic 2 – what is a provider and what does `static get parameters()` do?

Therefore, in what occasion I should return and what variables do I return?

Leave a Reply

2 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

In ES6 dependency injection gets the list of types it needs to resolve and pass instances for to the constructor of the class.

It has to be static, otherwise they could not be read before an instance is created.

In TypeScript it can aquire these types from the constructor parameters if they are applied (or @Inject() annotations).

Return the types for the constructor parameters of your class in the order they are listed in the constructor parameter list.

See https://stackoverflow.com/a/34546344/217408 for an example.


In fact, Angular2 tries to find out what to inject into the constructor of the class using the parameters method of the ReflectionCapabilities class: https://github.com/angular/angular/blob/master/modules/angular2/src/core/reflection/reflection_capabilities.ts#L126 This method tries several things: within the parameters of the type (i.e. a class property, i.e. static property) @Component({ (...) }) export class SomeComponent { constructor(http) { } static get parameter() { return [[Http]]; } } within the parameters metadata for the class if any. It’s populated by @Inject decorator. Not that parameter decorators aren’t supported in ES6 @Component({ (...) }) export class SomeComponent { constructor(@Inject(Http) http) { // == http:Http } } within the… Read more »