ui-select的默认值,之前在写angular下拉框时,画面初始化时需要设置初始值但是用ng-model绑定时,默认值一直没有出来
<div class="col-sm-3">
<ui-select ng-model="enterprise" theme="bootstrap">
<ui-select-match placeholder="请选择">{
{$select.selected.companyName}}</ui-select-match>
<ui-select-choices repeat="x in enterprises">
<small ng-bind-html="x.companyName"></small>
</ui-select-choices> </ui-select>
</div>
最初,ng-model=“enterprise” 的值是
$scope.enterprise = “XXXXX”(后台或其他页面传过来的);
在页面中值为空,一直以为ui-select默认值是这样正常简单绑定,比如类似其他的
<div class="col-sm-3 control-label">
<input type="text" class="form-control" placeholder="单位:吨" ng-model="enterprise">
</div>
这样,但这样写画面的值一直是没有的,后来想到在&
Angular UI-Select设置初始值

本文记录了在Angular项目中使用ui-select组件时遇到的问题。在页面初始化时,通过ng-model绑定默认值未显示。解决方案是将默认值设置为与选项对应的JSON对象,而不是简单的字符串。同时,需要注意在默认情况下检查选项,并确保后端也进行相应的检查。
最低0.47元/天 解锁文章
8205

被折叠的 条评论
为什么被折叠?



