21

.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)?

Sampath
  • 63,341
  • 64
  • 307
  • 441
  • 1
    The warning is because `private` properties are only used within the component they're defined. If you want to use a property in the view (and thus, outside of that component), you need to declare it as public. So using `private` properties in the views is not a good practice at all. – sebaferreras Aug 05 '17 at 11:36
  • 1
    Actually, this is a problem with `AoT`.You can see a great discussion about this on the below answer's link.It was huge discussion and great one too @sebaferreras – Sampath Aug 05 '17 at 15:20

1 Answers1

22

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

Sampath
  • 63,341
  • 64
  • 307
  • 441
Amit
  • 4,274
  • 21
  • 25