3

I am new to Angular JS.

I am trying to clear all the option values from the dropdown except the default "---select---" option.

But then an extra blank option is being created in the dropdown. I am unable to remove this blank option

Probably because $scope.screenResponse is empty. How can I make the dropdown with just the "---Select---" option?

JS Controller code:

delete $scope.screenResponse;

HTML code:

<select ng-model="messageSource" name="messageSource" ng-options="object.id as object.value for object in screenResponse ">
        <option value="" >--Select--</option>
</select>
firstpostcommenter
  • 2,328
  • 4
  • 30
  • 59

2 Answers2

1

Try this

$scope.screenResponse = "";

Demo Here

Shrinivas Pai
  • 7,491
  • 4
  • 29
  • 56
0

Do this inside your controller code where you performed delete

$scope.screenResponse.length = 0;

Setting the length property of an array to zero will make it empty.

Reference: How do I empty an array in JavaScript?

Demo: http://jsfiddle.net/codeandcloud/amw94yn4/

Community
  • 1
  • 1
naveen
  • 53,448
  • 46
  • 161
  • 251