What is static get parameters() purpose in Ionic 2?

前端 未结 1 1835
失恋的感觉
失恋的感觉 2021-01-03 08:46

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

export class ListPage {    
static get parameters() {
        re         


        
相关标签:
1条回答
  • 2021-01-03 09:25

    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.

    0 讨论(0)
提交回复
热议问题