Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with build --prod & templates since angular/cli 1.0 #5623

Closed
LapassetAlexis opened this issue Mar 24, 2017 · 67 comments
Closed

Error with build --prod & templates since angular/cli 1.0 #5623

LapassetAlexis opened this issue Mar 24, 2017 · 67 comments
Assignees
Labels
needs: investigation Requires some digging to determine if action is needed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful

Comments

@LapassetAlexis
Copy link

LapassetAlexis commented Mar 24, 2017

Bug Report or Feature Request (mark with an x)

- [x] bug report
- [ ] feature request

Versions.

$ ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ ? \ | '
\ / _ | | | | |/ _ | '
| | | | | | |
/ ___ | | | | (
| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
@angular/cli: 1.0.0
node: 6.9.2
os: win32 x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0
@angular/compiler-cli: 2.4.10

Repro steps.

ng build all is OK
ng build --prod is KO since morning after update to angular/cli 1.0

I have one class Field with attributes :

export class Field {
    key: string;
    type: string;
    label: string;
    order: number;
    fields: Array<Field>;
    validators: FormValidators;
    attributes: Attributes;
}

And this :

export class Attributes {
    canBeCreated: boolean;      // Apparait dans le formulaire de création
    canBeEdited: boolean;       // Apparait dans le formulaire de modification
    canBeFiltered: boolean;     // Apparait dans les filtres
    canBeSorted: boolean;       // Permet le tri sur la colonne
    isInList: boolean;          // Apparait dans la liste
    isInDetail: boolean;        // Apparait dans le détail
    placeholder: string;        // Texte qui apparait quand le champ est vide lors de la création ou modification

    constructor (attr: Attributes) {
        this.canBeCreated = attr && attr.canBeCreated ? attr.canBeCreated : true;
        this.canBeEdited = attr && attr.canBeEdited ? attr.canBeEdited : true;
        this.canBeFiltered = attr && attr.canBeFiltered ? attr.canBeFiltered : true;
        this.canBeSorted = attr && attr.canBeSorted ? attr.canBeSorted : true;
        this.isInList = attr && attr.isInList ? attr.isInList : true;
        this.isInDetail = attr && attr.isInDetail ? attr.isInDetail : true;
        this.placeholder = attr && attr.placeholder ? attr.placeholder : '';
    }
}

export class CheckboxAttributes extends Attributes {
    options: Array<{label: string, value: string}>;  // Liste des valeurs possibles de les checkbox
    isBinary: boolean;                               // Choix true/false ou multiple

    constructor(attr: CheckboxAttributes) {
        super(attr);
        this.options = attr && attr.options ? attr.options : null;
        this.isBinary = attr && attr.isBinary ? attr.isBinary : false;
    }
}

In my component checkbox.component.html :

    <div *ngIf="!field.attributes.isBinary">
         .....
    </div>

The log given by the failure.

ERROR in C:/Users/LAPASSAL/Projects/marty/src/$$_gendir/app/generic/components/checkbox-input/checkbox-input.component.ngfactory.ts (377,66): Property 'isBinary' does not exist on type 'Attributes'.
C:/Users/LAPASSAL/Projects/marty/src/$$_gendir/app/generic/components/checkbox-input/checkbox-input.component.ngfactory.ts (380,61): Property 'isBinary' does not exist on type 'Attributes'.

In typescript can I cast the object type to CheckboxAttributes with (this.field.attributes as CheckboxAttributes).isBinary ? false : [] but how can I do this in template? Any idea ?

Thx

@LapassetAlexis LapassetAlexis changed the title Error with build --prod & templates Error with build --prod & templates since angular/cli 1.0 Mar 24, 2017
@edemirkan
Copy link

Hi, there's literally no isBinary property for the Attributes class. So it's normal that this fails because your are checking boolean value of something undefined.

@LapassetAlexis
Copy link
Author

LapassetAlexis commented Mar 24, 2017

but my field.attributes can a Attributes or a CheckboxAttributes
it is dynamic

@hccampos
Copy link

We are getting hundreds of errors in our AoT build too after the upgrade. Even lots of errors in external libraries that worked just fine in all the RCs (both of Angular and the CLI):

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/button/mdl-button.component.ngfactory.ts (1,1): 'l' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/button/mdl-button.component.d.ts.MdlButtonComponent_Host.html (2,1): '$event' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/checkbox/mdl-checkbox.component.d.ts.MdlCheckboxComponent_Host.html (2,1): '$event' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/chips/mdl-chip.component.d.ts.MdlChipComponent.html (5,5): '$event' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/dialog-outlet/mdl-dialog-outlet.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/dialog-outlet/mdl-dialog-outlet.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/icon/mdl-icon.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/icon-toggle/mdl-icon-toggle.component.d.ts.MdlIconToggleComponent_Host.html (2,1): '$event' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/radio/mdl-radio.component.d.ts.MdlRadioComponent_Host.html (2,1): '$event' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/snackbar/mdl-snackbar.service.d.ts.MdlSnackbarComponent.html (5,7): '$event' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/switch/mdl-switch.component.d.ts.MdlSwitchComponent_Host.html (2,1): '$event' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/table/mdl-table.component.d.ts.MdlTableComponent.html (7,18): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/table/mdl-table.component.d.ts.MdlSelectableTableComponent.html (7,18): '$event' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/menu/mdl-menu-item.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout.component.d.ts.MdlLayoutComponent.html (13,9): '$event' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout-header.component.d.ts.MdlLayoutHeaderComponent.html (11,15): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout-header.component.d.ts.MdlLayoutHeaderComponent.html (16,15): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout-header.component.d.ts.MdlLayoutHeaderComponent.html (6,12): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout-header.component.d.ts.MdlLayoutHeaderComponent_Host.html (2,1): '$event' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-drawer.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-content.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-header-row.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-title.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-spacer.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/tabs/mdl-tab-panel.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/tabs/mdl-tabs.component.d.ts.MdlTabsComponent.html (5,9): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/tabs/mdl-tabs.component.d.ts.MdlTabsComponent.html (12,9): '$event' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/textfield/mdl-textfield.component.d.ts.MdlTextFieldComponent.html (51,7): '$event' is declared but never used.

ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/dialog-outlet/mdl-backdrop-overlay.component.ngfactory.ts (1,1): 'l' is declared but never used.

ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/dialog/mdl-simple-dialog.component.d.ts.MdlSimpleDialogComponent.html (8,9): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/dialog/mdl-simple-dialog.component.d.ts.MdlSimpleDialogComponent_Host.html (2,1): '$event' is declared but never used.

@rainstormza
Copy link

rainstormza commented Mar 24, 2017

screen shot 2560-03-24 at 20 03 03

ERROR in /Users/ARM/Desktop/kibito_web/src/$$_gendir/app/admin/member/member-add/member-add.component.ngfactory.ts (1627,45): Property 'member_name' is private and only accessible within class 'MemberAddComponent'.

hundreds of errors in our AoT happen after upgrade cli 1.0.0 (from beta 32)
using
ng build is ok
but ng build -prod not ok

@clydin
Copy link
Member

clydin commented Mar 24, 2017

AOT (which is enabled via --prod) requires that any property/field/function accessed from within a template be public. This is an Angular restriction. Previously this would only be represented as either a runtime error or unexpected behavior (depending on the usage).

@rainstormza
Copy link

rainstormza commented Mar 24, 2017

ng build -prod (work fine)

export class AppComponent {
  title = 'app works!';
}

but if I use private variable

export class AppComponent {
  private title = 'app works!';
}

error happens
ERROR in /Users/ARM/Desktop/kibito-ang4/src/$$_gendir/app/app.component.ngfactory.ts (1,1): Property 'title' is private and only accessible within class 'AppComponent'.

Does that mean we have to change all private variable to public variable ?

@clydin

@edemirkan
Copy link

edemirkan commented Mar 24, 2017

@rainstormza unfortunately yes. You need to update all variables used in the template as public.

@LapassetAlexis
Copy link
Author

@clydin all variables used in template :)

@clydin
Copy link
Member

clydin commented Mar 24, 2017

Yes. I know this is unfortunate for those with large applications and it seems counter-intuitive from an encapsulation perspective, but Angular's AOT mode requires it and these errors were actually always present just not reported.

@edemirkan
Copy link

edemirkan commented Mar 24, 2017

@clydin not to complain, but could have informed the developer such as "Using private template variables is deprecated and will be removed in final release. Please use public"

@cexbrayat
Copy link
Member

@demirk4n It has been the case for a long time, it's just that the CLI was not showing the errors reported by the Angular compiler when building with AoT (that was a bug). It has been fixed just before the 1.0 release.

@e-oz
Copy link

e-oz commented Mar 24, 2017

@clydin no, it's not Angular restriction. rc5 was compiled successfully with same code (and without errors in runtime) and 1.0 can't be compiled.

@filipesilva filipesilva added needs: investigation Requires some digging to determine if action is needed package4: @angular-sdk/webpack P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful labels Mar 24, 2017
@filipesilva
Copy link
Contributor

filipesilva commented Mar 24, 2017

I think this has been there for a while with the AOT compiler itself but as @clydin said we were not reporting it in the CLI, and that changed in #5601.

This can be reproduced in a brand new project by doing the following change (different from original issue but same root cause):

export class AppComponent {
  private title = 'app works!';
}
ERROR in D:/sandbox/experimental-proj/src/$$_gendir/app/app.component.ngfactory.ts (1,1): Property 'title' is private and only accessible within class 'AppComponent'.

I agree that this is very bothersome for existing projects trying to upgrade.

The only workaround I found to bypass this for now is doing the following:

npm install --save-dev @ngtools/[email protected]
rm -rf node_modules/\@angular/cli/node_modules/\@ngtools/webpack/

This is not optimal and does not carry over on reinstalls.

EDIT: a better workaround is to use @angular/[email protected] instead, as it carries over reinstalls and there isn't a big difference between the two versions.

@e-oz
Copy link

e-oz commented Mar 24, 2017

I just compiled ng build --prod --aot successfully with Angular 1.0 (release) and AngularCLI 1.0.0-rc.2. Works just fine. But AngularCLI 1.0 (release) can't compile same code. So it's not the Angular issue.

@filipesilva
Copy link
Contributor

filipesilva commented Mar 24, 2017

By "AOT compiler" I meant the ngc binary. If you try using it directly on your project you will get the same error (warning: this will generate .ngfactory.ts files and others):

$ $(npm bin)/ngc src/tsconfig.app.json
Error at D:/sandbox/experimental-proj/src/app/app.component.ngfactory.ts:31:30: Property 'title' is private and only accessible within class 'AppComponent'.

What was happening was that the CLI on older versions was always swallowing these errors.

@e-oz
Copy link

e-oz commented Mar 24, 2017 via email

@clydin
Copy link
Member

clydin commented Mar 24, 2017

They are actual errors. Angular's AOT mode requires public access; it is not a CLI limitation.

@e-oz
Copy link

e-oz commented Mar 24, 2017 via email

@billdwhite
Copy link

@clydin I'm not sure I understand. You say they are "actual errors", but I'm confused as to why they were not "actual errors" yesterday with rc.4? I got several warnings but the app ran fine. Today it won't even compile. Was my app missing functionality yesterday that I'm not aware of? And will that be restored once I sift through my code and switch every template-accessed variable to public?

@filipesilva
Copy link
Contributor

@billdwhite see my comment above: #5623 (comment)

What was happening was that the CLI on older versions was always swallowing these errors.

@billdwhite
Copy link

Thanks @filipesilva. I now understand what caused it, but why the requirement? Seems like template variables being private (or at least protected) makes more sense than exposing everything the template is using within it's own component to the outside world......just my view on it.

@e-oz
Copy link

e-oz commented Mar 24, 2017

Issue is not only with private/public variables, please don't convert it to simple private to public replacement. There are also errors like "value ISomeType can't be assigned to boolean" (just compiler's fault) or when variable is declared in template (#var) and compiler complains that there is no such field in component.

@filipesilva
Copy link
Contributor

filipesilva commented Mar 24, 2017

@billdwhite I am not the right person to ask about the requirement. It is an AOT Compiler requirement, and the CLI just uses an implementation of it via @ngtools/webpack.

Issues with the AOT compiler per se are better suited for https://github.com/angular/angular as that's the right repository.

It was a CLI bug that we were ignoring that whole class of errors though. And the result is that until now CLI users had AOT errors in their projects that we weren't showing, and so they never had a chance to fix them.

Like @e-oz said, it's not just private/public properties, it's other AOT errors as well.

Now all these errors appear all at once which is hard to deal with.

EDIT: this is the original issue that needed fixing: #4538

@hansl
Copy link
Contributor

hansl commented Mar 24, 2017

We always swallowed TS errors on templates, and now we report them as errors. I'm looking into reporting warnings as warnings instead, which seems to be the case here.

@edemirkan
Copy link

edemirkan commented Mar 25, 2017

@istiti if you are doing long term jobs you need to keep your libraries stable enough and plan migrations accordingly.I know a lot of shops using AngularJS - not even 2.x just for the sake of stability. You can't expect any software to be %100 bug free on day one. Furthermore you can upgrade your global @angular/cli to 1.0 and use rc.4 locally.

@elvisbegovic
Copy link
Contributor

@demirk4n u r totally right, i just expect from cli to write in even ONE LINE in console that im using private in template even if it compile aot (i assum its beta but not serious at all)

Cheers

@ojourmel
Copy link

ojourmel commented Mar 26, 2017

@e-oz

What about service ? I have to change private to public too ?

No. If your template isn't trying to use fields of service class, but I have never seen such cases.

I understand the restrictions AOT places on the angular team, but this use case happens often when managing authenticated state:

In this case, some nav template is referencing the AuthService, which has been injected into the component as private authService, to check user login state

  <!-- We are going to use the authService.loggedIn() method to see if the user is logged in or not. If they are not logged in we'll encourage them to login, otherwise if they are logged in, we'll provide a handy link to private deals. We haven't implemented the authService yet, so don't worry about the functionality just yet -->
  <div class="col-sm-12" *ngIf="!authService.loggedIn()">
    <div class="jumbotron text-center">
      <h2>Get More Deals By Logging In</h2>
    </div>
  </div>

  <div class="col-sm-12" *ngIf="authService.loggedIn()">
    <div class="jumbotron text-center">
      <h2>View Private Deals</h2>
      <a class="btn btn-lproperyg btn-success" routerLink="/special">Private Deals</a>
    </div>
  </div>

Reference: https://auth0.com/blog/angular-2-authentication/

The angular docs them self reference the use of an AuthService.isLoggedIn property [1]

Directly using service methods or properties in templates, especially when combined with the async pipe, it not completely out of the question.

@e-oz
Copy link

e-oz commented Mar 26, 2017

@ojourmel in your example you are using publicly accessed method, not private field :) I mean, in case of services it's easy to predict what property will be used outside to make this field public. But yes, maybe my initial statement was too broad :)

@harilal
Copy link

harilal commented Mar 26, 2017

@filipesilva @hansl it's good to show the errors. But we need to address it in changelog as breaking change. Developers like myself were developing production apps find this very disturbing. Since we need to change almost all the source files. It would be better to address it in breaking change, so that we won't get panicked.

@ojourmel
Copy link

@e-oz
Unless I am mistaken, this is still an issue. Even though I am accessing a public method or property, I am doing it via the private authSerivce instance, that was injected into the component.

In this way, AOT will fail to allow me to use the authService object in the template, since it is private. Thus, the only way to use services in templates directly, would be to make them public. This is problematic, as services are essentially singletons, managed by the dependency injection framework, and can have far reaching impacts on your application.

I have done up a very small project to demo this issue: https://github.com/ojourmel/demoAOTPrivateIssues

@webcat12345
Copy link

Thanks guys for all comments above.

I am Angular2 crazy follower and recommended ng2 to client. :) also upgrading ng versions immediately when new version is released.

But Today I got a lots of errors while building product and it make all of us frightened. :(

I will try to migrate all private properties to public but I hopes this issue would be solved soon from respected angular team :)

@elvisbegovic
Copy link
Contributor

thanks to team for this breakin change

@emreavsar
Copy link

so, everybody is complaining about these problems, but nobody provides a solution?

what's the best practice here?

  • not declaring private or public
  • declaring public
  • getter around it?

thanks

@elvisbegovic
Copy link
Contributor

it's simple, aot require all members you use outisde your class be public. But this cli console, doesn't tell us before relase! Team forget people using cli since a while with big project, response: we have to KNOW that for aot all members are public !

I can say too:

we have to know that when using var a:number = "bonjour" will throw error why show it in console ? LOL

maybe now cli is good, but before release cli was 💩

@xiluo58
Copy link

xiluo58 commented Mar 27, 2017

Is there a tool to check this kind of error? I remember ng lint reports these errors before, but doesn't do it now.
I am using @angular/cli 1.0, default dependencies versions and default settings.

@basst314
Copy link

I'm also looking for a best practice here.
In addition to @emreavsar 's suggestions it would also be reasonable to

  • leave your field private, but add a public getter(/setter) if you need access.

This aligns pretty well with common encapsulation conventions with the only downside to write a little more code.

@webcat12345
Copy link

webcat12345 commented Mar 27, 2017

Thanks for your comment @basst314. But Too many codes should be modified. That is not good option.
Anybody please let me know the version of dependencies I can use without any modification.

{
  "name": "ng-reason",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/cli": "^1.0.0-rc.4",
    "@angular/common": "~2.4.4",
    "@angular/compiler": "~2.4.4",
    "@angular/core": "~2.4.4",
    "@angular/forms": "~2.4.4",
    "@angular/http": "~2.4.4",
    "@angular/platform-browser": "~2.4.4",
    "@angular/platform-browser-dynamic": "~2.4.4",
    "@angular/router": "~3.4.4",
    "@types/google-maps": "^3.2.0",
    "angular2-tag-input": "^1.2.1",
    "core-js": "^2.4.1",
    "ng2-bootstrap": "^1.2.6",
    "ng2-bs3-modal": "^0.10.4",
    "ng2-map": "^0.16.3",
    "ng2-table": "^1.3.2",
    "rxjs": "5.2.0",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/node": "^7.0.0",
    "@angular/cli": "^1.0.0-rc.4",
    "codelyzer": "~3.0.0-beta.4",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "3.2.0",
    "karma": "1.5.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.6.0",
    "protractor": "5.1.1",
    "ts-node": "2.1.0",
    "tslint": "4.5.1",
    "typescript": "2.2.1"
  }
}

Here is my package.json. Thanks.

@edemirkan
Copy link

@basst314 getters/setters are fine if there's a business requirement to modify underlying private property. Apart from that, just for template binding - get/set creation is somewhat overkill.

  private _authenticatedUser$: BehaviorSubject<IAuthenticatedUser> = new BehaviorSubject<IAuthenticatedUser>(null);

  public get user(): Observable<IAuthenticatedUser> {
    return this._authenticatedUser$ as Observable<IAuthenticatedUser>;
  }

@basst314
Copy link

What would you suggest @demirk4n ?
Somewhat the decision has been made that the template is not part of the component (somehow weird for me), so private variables are not accessible.
Making everything public doesn't feel right to me (coming from Java world).

@elvisbegovic
Copy link
Contributor

You seems don't know how template and class are connected. For me there is sens to have it punlic only reclamation goes to cli that doesn't inform us with error in console !

@basst314

@edemirkan
Copy link

@basst314 I'd just use public properties for basic template stuff and getter/setters to wrap around a more complex business logic for a private property.

One can hope, maybe in the next iteration of ES Microsoft may surprise us with a C# get/set functionality :)

public string Name { get; set; }

which will be equal to

private string name;
public string Name
{
    get
    {
        return this.name;
    }
    set
    {
        this.name = value;
    }
}

@thaihacong
Copy link

thaihacong commented Mar 27, 2017

It seems that Angular 4.0 is not able to recognize the local variable inside ngFor loop.

<div class="row" *ngFor="let employee of employees; let i = index; trackBy: employee?.uuid">
  <employee-details [id]="generateId(employee.date)" [(employee)]="employees[i]">
  </employee-details>
</div>

ng build --prod returns

ERROR in ng://../src/app/employees.component.html (175,32): Property 'employee' does not exist on type 'EmployeesComponent'.

In EmployeesComponent, I declared employees: Employee[];, but not employee: Employee.
This worked well before without such warning messages.

UPDATE:
If I remove trackBy: employee?.uuid, ng build --prod is OK.

So, the problem could be related to trackBy in this case.

@harilal
Copy link

harilal commented Mar 27, 2017

@thaihacong
https://toddmotto.com/angular-ngfor-template-element

i think these needs to be as directives.

@thaihacong
Copy link

@harilal
I updated my comment. The problem could be related to trackBy.

@elvisbegovic
Copy link
Contributor

elvisbegovic commented Mar 27, 2017

trackBy is now function! how you use trackBy is bad. please check docs it's function that retunr id
Cheers

@thaihacong

@hansl
Copy link
Contributor

hansl commented Mar 27, 2017

I'm locking this discussion down. The original issue is being worked on and the discussion is getting a bit out of hand here.

@angular angular locked and limited conversation to collaborators Mar 27, 2017
@hansl
Copy link
Contributor

hansl commented Mar 27, 2017

@alapasset Regarding your original issue:

The following code in Typescript will not compile:

interface A {
  aValue: number;
}
interface B {
 aValue: number;
 bValue: string;
}

function a(aOrB: A | B): string {
  const x = aOrB.aValue;  // Valid. aValue is part of both interfaces.
  const y = aOrB.bValue;  // ERROR. bValue is not part of A.
}

a({ aValue: 1 });

I think this comes from a misunderstanding of what the A | B typing does. It's not valid to use either types as if the value passed in is either. You can only use properties that are part of both typings, since you don't know which one is passed.

You need to change your typings to reflect the code, or typecast it if possible.

I'm going to close this issue. I have a PR to move warnings in templates as warnings, but it's not a fix for this issue.

@hansl hansl closed this as completed Mar 27, 2017
@hansl
Copy link
Contributor

hansl commented Mar 28, 2017

#5698 fixed typescript messages and warnings to not be considered errors. Please note this will not remove errors from your templates from being reported.

dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this issue Apr 23, 2018
Previously, we were reporting all diagnostics as errors. Now only Typescript errors
will be reported as real errors to webpack. Messages and warnings will be warnings.

Fixes angular#5623
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: investigation Requires some digging to determine if action is needed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful
Projects
None yet
Development

No branches or pull requests