Computer >> Computer tutorials >  >> Programming >> Javascript

Setting null values with an HTML <select> using AngularJS.


To set null values, here is the controller −

function display($scope) {
   $scope.obj ={"selected":null};
   $scope.objects = [{id: 1, value: "Yes"}, {id: 0, value: "No"}]
}

The following is the template −

<div ng-controller = "display">
   <select ng-model = "obj.selected"
      ng-options = "value.id as value.value for value in objects">
      <option value = "">Unknown</option>
   </select>
<br/>
   {{obj}}
</div>