Search code examples
jsonangularangular4-formsangular4-httpclient

Property 'ResultJson' does not exist on type 'Book[]'


I am using angular 4 and getting this error when i am running ng build --prod. Its not giving any error on running ng-serve and works fine. ResultJson is my JSON file. If i remove ResultJson, it doesn't show any data on UI. Help will be much appreciated. Thank you.

Here is my html file.

<div *ngIf="books?.ResultJson.length === 0">
    <h4>no result found</h4>
</div>

<div *ngIf="books?.ResultJson.length > 0">
    <form>
        <table>
            <tr>
                <td><h4>Name</h4></td>
                <td><h4>Id</h4></td>
            </tr>
            <tr *ngFor="let b of book?.ResultJson">
                <td>{{p.name}}</td>
                <td>{{p.id}}</td>
            </tr>
        </table>
    </form>

this is the array in my typescript file

books: Book[] = [];

Solution

  • Its the problem with AOT. Instead of ng-build --prod, if i run ng build --prod --aot false it works fine. Don't know what is the exact solution but it made my code work fine.