Home > other >  Can I change something so Angular shows more errors either on Build or at least in Runtime?
Can I change something so Angular shows more errors either on Build or at least in Runtime?

Time:01-27

This code works, because the item object has isOk (boolean) property.

<span *ngIf="item.isOk===true"><fa name="fas fa-check"></fa></span>

This code does not work, because the item object has NO isCucuBau (boolean) property.

<span *ngIf="item.isCucuBau===true"><fa name="fas fa-check"></fa></span>

But my problem is that the 2nd code is not giving any error to me on ng build --prod, and it also does not say anything at runtime, the browser just doesn't do anything (empty space instead of the checkmark), and there is also zero error in the Console.

Is there anything that I can do to get any kind of feedback when compiling, or at least in the browser? Or this is something that Angular is not capable of doing?

If I have a textbox, and I put [value]="n/a" then the compiler shows me that there is no variable called n/a, and I think this issue above is similar to that.

Angular CLI: 12.2.11, 8.2.14

node -v: v16.13.0

npm --version: 8.1.0

CodePudding user response:

You can enable strictTemplates in your angularCompilerOptions inside tsconfig[.app].json.

The basic mode states to do exactly what you need, ie:

If you write <map [city]="user.address.city">, the compiler verifies the following:

  • user is a property on the component class
  • user is an object with an address property. <-- Your use case
  • user.address is an object with a city property

CodePudding user response:

Is possible to do that, you can try used safe navigation operator.

from this : item.isCucuBau===true

to this: item?.isCucuBau===true

  • Related