Hello,

In this example <http://plnkr.co/edit/y67Ex1OA4eajelOWQIO7?p=preview> I 
have a simple select

<select ng-model="myColor" ng-options="color.name for color in colors">
    <option value="">-- choose color --</option></select>

With three colors and a button to delete the last one

<button ng-click="delRed()">Delete red</button><br/>

JS code looks like that

angular.module('selectExample', []).controller('ExampleController', ['$scope', 
function($scope) {
  $scope.colors = [
    {name:'black'},
    {name:'white'},
    {name:'red'},
  ];
  $scope.myColor = $scope.colors[2]; // red
  $scope.delRed = function(){        
    $scope.colors.length = 2;
  }}]);

When red is selected and clicking on "Delete red " the -- choose color -- 
option 
is selected, but the model {{myColor}} is

{"name":"red"}

how can I set it to null (or empty string or any "empty" value) in case red 
was selected and is deleted in order to have it coherent with value?


This is a simplified version of the example in AngualrJS documentation, and 
in that example there is the same issue. Once the item doesn't exist I 
would expect the model to reflect that. Is this a limitation of AngularJS 
or am I missing something?

(Question already posted 
on 
http://stackoverflow.com/questions/25367105/updating-model-when-selected-item-is-deleted)


Regards
Paolo

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to