The Angular AOT compiler does not fail when using a non existing property in a template if the usage is wrapped in an *ngIf directive.
E.g. in this example, custom does not have a property property defined:
<div *ngIf="condition">
{{ custom.property }}
</div>
Why does the Angular compiler not fail on this code? Is there a way to instrument it to do so?
And just for clarification, it fails with this code as expected:
<div>
{{ custom.property }}
</div>
I'm currently thinking of creating a custom lint script that would remove all *ngIfs from the code and do an AOT build to check that all properties do exist. Is that a valid idea? And if so, why do I have to do this in the first place?
I'm using Angular 5, but I think it doesn't work in newer versions either.
I found that the Angular Language service is able to report these errors (in VS Code or IntelliJ IDEA). So it should be possible.
Object.definePropertyfor instance) that you can't check for in an AOT build. I don't think removing these is necessary. It seems a bit opinionated - what happens to the properties not wrapped in an*ngIfdirective? Angular templating has an "safe navigation operator" syntax similar to Swift's optionals. You can rewrite your templates to usecustom?.property, see angular.io/guide/…