title: Changing a dropdown value results in: Cannot read property entityState of undefined
body: <p>I'm working on an existing AngularJS app where I need to add a new view.  In the new view, there is a dropdown which triggers this error every time the value is changed.  The dropdown loads all the data correctly.  It's only when the value is changed that something goes wrong.</p>
  
  <pre><code>&lt;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"&gt;
      &lt;option value=""&gt;-- Select a State --&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Here's the error:</p>
  
  <pre><code>TypeError: Cannot read property 'entityState' of undefined
  </code></pre>
  
  <p>Drilling into the first line on the stack trace, the error is happening here:</p>
  
  <pre><code>https://localhost:44398/bower_components/breezejs/breeze.debug.js:5284:20
  </code></pre>
  
  <p>It's inside this method:</p>
  
  <pre><code>function setNpValue(context, rawAccessorFn)
  </code></pre>
  
  <p>Here's the 'context' object.  It all looks good:</p>
  
  <pre><code>context: Object
  entityAspect: EntityAspect
  newValue: "AL"
  oldValue: null
  parent: Retailer__Model
  property: NavigationProperty
  propertyName: "state"
  __proto__: Object
  </code></pre>
  
  <p>Down inside the method is where the error is happening.  </p>
  
  <pre><code>if (newValue != null) {
      var newAspect = newValue.entityAspect;
      if (entityManager) {
          if (newAspect.entityState.isDetached()) {
              if (!entityManager.isLoading) {
                  entityManager.attachEntity(newValue, EntityState.Added);
              }
  </code></pre>
  
  <p>NewValue is accurately reflecting the new value I selected ("AL" in this case), so it is not null.  However, on the next line down, newValue.entityAspect is undefined, so newAspect also ends up being undefined. As a result, when we get to this line:</p>
  
  <pre><code>newAspect.entityState.isDetached()
  </code></pre>
  
  <p>The error occurs.</p>
  
  <p>I can post the entire controller for the view of where the dropdown exists, if that will help.  But it seems like overkill. Looking for any help I can get.  I'm pretty new to Angular.</p>
  
  <p><strong>EDIT / UPDATE:</strong></p>
  
  <p>I thought I had found the solution.  As the solution to this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/33786086/dropdown-in-angularjs-has-correct-text-but-wrong-value">Dropdown in AngularJS has Correct Text, but Wrong Value</a></p>
  
  <p>I had added "track by state.code" to the dropdown.  In trying to troubleshoot THIS problem, I removed it.  After a refresh, this error went away.  WAHOO!  But my joy was short lived.  A short time later, the error came back.  And now I'm back to square one.</p>