Reputation: 4815
I was building an Angular 4 and it runs completely fine in the developer server and without the --prod
flag but as soon as I ran ng build --prod
on My Angular 4 Project but it gives the following output:
PS: It's built using ng cli version 1.4.2
Variable that is giving error:
userHotelLength = '0';
Output:
Date: 2018-01-24T17:25:24.719Z
Hash: a7059ea62cc4eeb37fde
Time: 12033ms
chunk {0} styles.c9da94e47a8635066285.bundle.css (styles) 142 kB {3} [initial] [rendered]
chunk {1} polyfills.3bc34265385d52184eab.bundle.js (polyfills) 86 bytes {3} [initial] [rendered]
chunk {2} main.e402deade8b026b7d50e.bundle.js (main) 84 bytes [initial] [rendered]
chunk {3} inline.9d07561b59257af76b95.bundle.js (inline) 1.45 kB [entry] [rendered]
ERROR in ng:///home/x/y/z.html (10,6): Operator '==' cannot be applied to types 'string' and 'number'.
ERROR in ng:///home/x/y/z.html (29,6): Operator '!=' cannot be applied to types 'string' and 'number'.
ERROR in ng:///home/x/y/z.html (36,6): Operator '==' cannot be applied to types 'string' and 'number'.
Code:
<div class="my-booking-card loading-card" *ngIf="userHotelLength == 0 && (!userCancelledHotels || !userBookedHotels)">
...
</div>
<div *ngIf="userHotelLength != 0 && (userCancelledHotels || userBookedHotels)">
...
</div>
<div class="no-hotel-found" *ngIf="userHotelLength == 0">
...
</div>
Upvotes: 1
Views: 3103
Reputation: 327
When you compare one type with other with AOT it gives error because it compiles at the time of build.
I your change variables type it will worked. You won't get idea until you compile code with AOT because at the development one generally don't serve with AOT.
Upvotes: 1
Reputation: 4815
Found the answer:
Change the variable type to any instead of string because we're comparing right:
userHotelLength: any = '0';
Upvotes: 0