加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular4_select设置默认选项

发布时间:2020-12-17 08:31:36 所属栏目:安全 来源:网络整理
导读:客户需求如上。 默认选中Pallet选项 百度,Google,给我的答案最好的是: option value="" 请选择/option使用的是value(这是HTML原生的属性) option *ngFor="let item of students" [value]='item'{{item}}/option 也就是value=''的时候会默认选中 后台处

客户需求如上。 默认选中Pallet选项


百度,Google,给我的答案最好的是:

<option value="">请选择</option>使用的是value(这是HTML原生的属性)

<option *ngFor="let item of students" [value]='item'>{{item}}</option>


也就是value=''的时候会默认选中

后台处理方法:

list.Insert(0,new { key = "Select Type",value = "" });


但是,并不能解决我的需求。


群里有人给我ng-switch-default

看的一脸懵逼


直接解决方法:

< select class= "form-control customSelect" [( ngModel)]= "packagingType" name= "packagingType" ( change)= "packagTypeChange(packagingtype.value)" # packagingtype>
< option * ngFor= "let type of packagingTypes" value= "{{type.value}}" >
{{type.key}}
</ option >
</ select >

// 后台获取完之后直接赋值
this. service. getStagePackingTypes(). subscribe(result => {
this. packagingTypes = result;
this. packagingType = 'PLT'
});

解决了。


最后再吐槽一下,原生的Select和input ='file' 和 shit一样

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读