angular.js - Angularjs select How to set an option to clear the selection
漂亮男人
漂亮男人 2017-05-15 17:06:05
0
1
521

I want to have an option whose value is null. When I select it, the content in the input can be cleared.
My html is written like this

<select 
        ng-options="x as (x.name+' '+x.id) for x in items| orderBy:'name'"
        ng-model="selectedItem" ng-change="update()">
        <option value="">---Please select---</option>
</select>

<input type="text" ng-model="name" name="name" class="space" placeholder="Name" disabled="true">
<input type="text" ng-model="id" name="suburb" class="space" placeholder="id" disabled="true">

My js is

update(){
    $scope.name=$scope.selectedItem.name;
    $scope.id=$scope.selectedItem.id;
}

After I select an option, the content of the two inputs below will change according to the option. But when I click please select, the previous content is still in the two inputs and is not cleared. I tried writing select as

<select class="form-control" ng-model="selectedItem" ng-change="update()">

                    <option value="">none</option>
                    <option value="1">1</option>
                    <option value="2">2</option>

</select>

The option none can play this role. . . What is the reason for this? How can I use angularjs's select to implement this function?

漂亮男人
漂亮男人

reply all(1)
淡淡烟草味
<input type="text" ng-model="selectedItem.name" name="name" class="space" placeholder="Name" disabled="true">
<input type="text" ng-model="selectedItem.id" name="suburb" class="space" placeholder="id" disabled="true">

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template