0
对我来说很奇怪的行为。我对Angular很新,可能我做错了什么。角度选择不反映其模型
这是我的情景:
HTML:
<div ng-controller="ExampleController">
<label>Color:
<select ng-model="myColor" ng-options="color.name for color in colors">
<option value="">-- choose color --</option>
</select>
</label>
<div>
<button ng-click="myColor = { name:'not in list', shade: 'other' }">clear</button>
</div>
</div>
JS:
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.colors = [
{name:'black', shade:'dark'},
{name:'white', shade:'light'},
{name:'red', shade:'dark'},
{name:'blue', shade:'dark'},
{name:'yellow', shade:'light'}
];
$scope.myColor = $scope.colors[2];
}]);
和这里的小提琴:
https://jsfiddle.net/t18uggqt/
有人可以帮助我,请理解为什么选择不反映模型(有只首选)
谢谢!
更新小提琴http://jsfiddle.net/Lvc0u55v/6755/ –