繁体   English   中英

类型“ Book []”上不存在属性“ ResultJson”

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

我正在使用angular 4并在运行ng build --prod时收到此错误。 它在运行ng-serve时没有给出任何错误,并且工作正常。 ResultJson是我的JSON文件。 如果我删除ResultJson,它不会在UI上显示任何数据。 帮助将不胜感激。 谢谢。

这是我的html文件。

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

这是我的打字稿文件中的数组

books: Book[] = [];

问题在于问号:> ? <不要使用*ngIf="books?.Resu...而是使用*ngIf="books && books.ResultJson.length > 0"或创建方法booksExists()if返回true / false(与book相同)这可能与AoT(时间提前-可能在生产编译中使用)有关-我在此角度框架中找到了此信息。

这是AOT的问题。 代替ng-build --prod ,如果我运行ng build --prod --aot false,它可以正常工作。 不知道确切的解决方案是什么,但这使我的代码工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM