angular.js - Angularjs select 如何设置一个选项可以清除所选内容
漂亮男人
漂亮男人 2017-05-15 17:06:05
[AngularJS讨论组]

我想要有一个选项,里面的值是null,当我选中它的时候,可以清除input里面的内容。
我的html是这样写的

<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">

我的js是

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

我选中一条选项之后下面的两个input会根据选项更改内容。但是我点击please select的时候两个input里面还是上一个内容,并没有清除。我试着把select写成

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

选项none就可以起到这个作用。。。这是什么原因呢?要怎么才能用angularjs的select来实现这个功能呢?

漂亮男人
漂亮男人

全部回复(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">

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号