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

丶灬走出姿态 提交于 2019-11-27 13:36:28

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!