我正在使用ng選項來爲我的選擇標籤選擇用戶。一切正常,但首次選擇一個選項後,默認空白值消失。如果我想再次恢復到默認值,該怎麼辦?如何做到這一點?我怎樣才能保留這個空白值?AngularJS ng-options在選擇選項後刪除了默認空白值
這裏是我的代碼示例:
<!DOCTYPE html>
<html ng-app="app">
<head>
<link rel="stylesheet" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-controller="myController">
<h1>Hello World!</h1>
<select ng-model="mySelection" name="" id="" ng-options="x.value as x.label for x in myOptions">
</select>
</body>
</html>
<script>
var app = angular.module('app', []);
app.controller('myController', function($scope){
$scope.myOptions = [{
"value": null,
"label": null,
},{
"value": "First",
"label": "First",
},{
"value": "Second",
"label": "Second",
},{
"value": "Third",
"label": "Third",
}]
});
</script>
這裏是plunker:http://plnkr.co/edit/5f17YxRfWFI4g40t3NEf?p=preview
嗨,當獲得值null調用函數 –
什麼函數?你能演示一個代碼嗎? –