Angular 2 Ahead-of-Time compiler: must I make all class properties public?

后端 未结 2 1789
天命终不由人
天命终不由人 2020-12-03 03:20

Angular 2 rc 6, typescript 2, node 4.5.0, npm 2.15.9 on Windows 7

I\'m trying to move from Just-in-T

相关标签:
2条回答
  • 2020-12-03 03:42

    So is too, in Final release of Angular 2 whit Ionic2 RC1

    A workaround for Fields could be to use getters without setters

    protected _myField: any;
    
    get myField(): any { 
      return this._myField; 
    }
    

    You can also see other JiT to AoT considerations to adapt your code in this blog of Isaac Mann

    1. const lambda => export function
    2. default export => named export
    3. private, protected accessors should be changed to public for any members accessed from template
    4. dynamic component template => static template
    5. moduleId should be set on components with templateUrl
    0 讨论(0)
  • 2020-12-03 03:54

    For a given component all its members (methods, properties) accessed by its template must be public in the ahead-of-time compilation scenario. This is due to the fact that a template is turned into a TS class. A generated class and a component are 2 separate classes now and you can't access private members cross-class.

    In short: you can't access private members in your templates if you want to use ahead-of-time compilation.

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