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/ –