Identifier refers to a private member of the component

痞子三分冷 提交于 2019-12-03 15:20:30

问题


.html

  <offline-picks *ngFor="let pick of pickData" [data]="pick"></offline-picks>

.ts

export class OfflineArticlesPage {
  private pickData: picksModel[] = [];
  constructor(private localCacheService: LocalCacheServiceProvider) {
  }
}

When I used the private member as shown above it shows below error.I'm using Angular Language Service extension on VS code editor.

[Angular] Identifier 'pickData' refers to a private member of the component

Hope using private members inside the component is good programming practice no? But as a solution for above issue was given as below comment on the extension's repo.

The language service will emit these errors because they will be errors during AOT. Eventually, you will need to resolve these.

We have plans to support access to private and protected members in AOT but that will not land until at least 6.0 (spring of next year).

So can you tell me what will be the best way to declare members on the components?

Update:

I use ionic cordova run android --prod --device CLI command with latest Ionic "ionic-angular": "3.5.3",.But it works nicely on my Android device.That means it is working fine with the AOT too no? Then why this error (or warning actually)?


回答1:


They have to be public in order for AoT to work.

See here for a bit more details: https://github.com/angular/angular/issues/11978



来源:https://stackoverflow.com/questions/45520838/identifier-refers-to-a-private-member-of-the-component

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