更改下拉值会导致:无法读取 属性 未定义的实体状态

Changing a dropdown value results in: Cannot read property entityState of undefined

我正在开发一个现有的 AngularJS 应用程序,我需要在其中添加一个新视图。在新视图中,每次更改值时都会触发此错误的下拉列表。下拉列表正确加载所有数据。只有改值的时候才会出问题。

<select class="form-control form-controls input-sm" ng-model="vm.retailer.state" ng-options="state.code as state.name for state in vm.states track by state.code">
    <option value="">-- Select a State --</option>
</select>

这是错误:

TypeError: Cannot read property 'entityState' of undefined

深入堆栈跟踪的第一行,错误发生在这里:

https://localhost:44398/bower_components/breezejs/breeze.debug.js:5284:20

在这个方法里面:

function setNpValue(context, rawAccessorFn)

这是 'context' 对象。一切看起来都不错:

context: Object
entityAspect: EntityAspect
newValue: "AL"
oldValue: null
parent: Retailer__Model
property: NavigationProperty
propertyName: "state"
__proto__: Object

在方法内部是发生错误的地方。

if (newValue != null) {
    var newAspect = newValue.entityAspect;
    if (entityManager) {
        if (newAspect.entityState.isDetached()) {
            if (!entityManager.isLoading) {
                entityManager.attachEntity(newValue, EntityState.Added);
            }

NewValue 准确反映了我选择的新值(在本例中为 "AL"),因此它不为空。但是,在下一行中,newValue.entityAspect 未定义,因此 newAspect 最终也未定义。结果,当我们到达这一行时:

newAspect.entityState.isDetached()

出现错误。

我可以 post 整个控制器来查看下拉菜单所在的位置,如果这有帮助的话。但这似乎有点矫枉过正。寻找我能得到的任何帮助。我是 Angular.

的新手

编辑/更新:

我以为我找到了解决办法。作为本题的解答:

我在下拉列表中添加了 "track by state.code"。在尝试解决此问题时,我将其删除。刷新后,此错误消失了。哇哦!但我的快乐是短暂的。不久之后,错误又回来了。现在我回到正题。

好的,我能够解决这个问题。只是它创造了另一个。这里的问题在于我如何构建下拉菜单:

<select class="form-control form-controls input-sm" ng-model="vm.retailer.state" ng-options="state.code as state.name for state in vm.states track by state.code">
    <option value="">-- Select a State --</option>
</select>

我改成了:

<select class="form-control form-controls input-sm" ng-model="vm.retailer.state" ng-options="state as state.name for state in vm.states">
    <option value="">-- Select a State --</option>
</select>

此错误消失了。但问题是,我添加了此更改以解决我在此处发布的问题:

所以现在我又开始尝试解决这个问题了。

当我将 angular 从 1.3.x 更新为 1.4.x 时,我 运行 也陷入了这个问题。当我转换回 angular 1.3.x 时,它就消失了。我假设 Breeze Angular 服务中有一些东西被 angular 破坏了并且还没有被 breeze 修复。