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

Bug Report or Feature Request (mark with an x)

- [x] bug report
- [ ] feature request


$ 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) {
        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">

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 ?


About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 67 (22 by maintainers)

Commits related to this issue

Most upvoted comments

@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”

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 ?


@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.

@istiti you know you can just lock your version to rc.4, right? It will all still work. Or even better, you can fork the CLI, do some fixes and submit a PR. It is OpenSource and nobody is under any obligation to concede to your demands.

The promise of a release candidate has also been broken - no breaking changes.

@e-oz I understand the pain. Our build also broke due to this (and our templates are good). But we just reverted to the previous CLI and that’s ok. The tone you are using is not very helpful, imho.

That’s why it’s good to use WebStorm with Typescript window open 😃 I’ve caught all these errors long time ago.

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

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 💩

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?


" AOT mode requires public access"

No. My internal class members are private. AOT is broken.

This is the same smell as making members public so that test frameworks can access them.

@billdwhite see my comment above:

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

@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.

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

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.