Angular 2 (+Dart) inline conditionals : Is the second condition evaluated if the first is false? 如何解决?

标签 angular dart angular-dart angular-template

这是我的component.html(Angular Dart 模板)中的代码:

<div *ngIf="selectedOffer!=null && !selectedOffer.isBotenOffer">...</div>

这是我得到的异常:

EXCEPTION: NoSuchMethodError: The getter 'isBotenOffer' was called on null. Receiver: null Tried calling: isBotenOffer

selectedOffer 我有时是 null。但是,如果第一个语句为假,为什么要对第二个语句进行评估?我怎样才能最好地解决这个问题?

最佳答案

Angular 会将其写入生成的模板文件中:

_NgIf_0_5.ngIf = ((ctx.selectedOffer != null) && !ctx.selectedOffer.isBotenOffer);

因此,如果 selectedOffernull,它不应评估 selectedOffer.isBotenOffer。但是,您可能遇到了一个刚刚在 dart2js 中修复的错误:https://github.com/dart-lang/sdk/commit/fe7baee84828e109a49920c2572f3917e5ff8ca5

如果您在组件的构造函数中设置 selectedOffer,但在构造函数中提前返回,则可能会遇到此问题。

关于Angular 2 (+Dart) inline conditionals : Is the second condition evaluated if the first is false? 如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43260815/

相关文章:

dart - Angular-dart:从属性自动转换组件的 @input 字段

javascript - 极速: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

javascript - Angular Material 6 Mat-Chip-List - 两个 mat-chip-list 声明共享相同的数据源

android - 在 Flutter 中调整手机亮度

flutter - 任务 ':app:mergeDebugShaders' Flutter 执行失败

css - Angular 2 Dart : How to add body class from inside component?

javascript - 如何使用 ng2-bootstrap 获取弹出窗口?

javascript - 检查给定 ID 是否存在于 Javascript 中的嵌套对象中的有效方法

flutter - 如何在 Flutter 中创建一个可以从屏幕底部滑动的页面?

angularjs - Angular Dart 和表单验证