2016-05-25 62 views
0

您好我正在創建角度js下拉列表,同時選擇一些空格將附加到下拉值的值。從下拉列表中選擇數據時的空格

模板

<div class="row control-group"> 
    <label class="col-xs-4 col-sm-4 col-md-3 col-lg-3 control-label">{{::'label.identity'|translate}}</label> 

    <div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls"> 
     <select id="selectIdentity" name="selectIdentity" required ng-trim="true" ng-change="changedValue(addUser.identityProvider)" ng-model="addUser.identityProvider" > 
     <!-- Empty option necessary for placeholder to work --> 
     <!-- <option value="">{{::'define.selectval'|translate}}</option> --> 
     <option ng-repeat="idprovider in identityProvider" 
       ui-select2="select2IdentityProvider" 
       class="selectIdentity" 
       ng-selected="identityProvider"     
       ui-select2="select2LocaleSettings"> 
      {{idprovider}} 
     </option>      
     </select> 
     <span class="help-block" 
       ng-show="addUserForm.selectIdentity.$error.required"> 
       {{::'error.required'|translate}} 
     </span> 
    </div> 
</div> 

JS代碼

$scope.identityProvider = ['Customer','Employee']; 
+0

UI,選擇2已經過時,你應該嘗試使用UI - 選擇:https://github.com/angular-ui/ui-select –

+0

沒有仍然不工作 – priyanka

+0

你能提供一個jsfiddle或什麼東西來顯示你到底是什麼問題? – ThomasS

回答

0

嘗試是這樣的: -

<select id="selectIdentity" name="selectIdentity" ng-model="addUser.identityProvider"> 
    <option value="">Select</option> 
    <option value="value 1">{{'Value 1'}}</option> 
    <option value="value 2">{{'Value 2}}</option> 
</select> 
+0

嘿用這種方式其工作,但我們必須做這個ng-repeat,就好像我們有這麼多的值 – priyanka

+0

yes然後做一件事,使用'標籤上不起作用,然後嘗試在一個'

0

此代碼測試,沒有白SPAC E:

<select class="select2_single form-control" ng-model="module_id" tabindex="-1" ng-init="get_model_value()" id="module_id"> 
<option ng-repeat="item in moduleData" ng-selected="item.selected" value="{{item.id}}">{{item.module}}</option> 
</select> 
0

這將隱藏在下拉列表中第一個空格

<option value="" selected hidden /> 

這個選擇隱藏將隱藏空白

<select id="selectIdentity" name="selectIdentity" required ng-trim="true" ng-change="changedValue(addUser.identityProvider)" ng-model="addUser.identityProvider" > 
     <option value="" selected hidden /> 
     <option ng-repeat="idprovider in identityProvider" 
       ui-select2="select2IdentityProvider" 
       class="selectIdentity" 
       ng-selected="identityProvider"     
       ui-select2="select2LocaleSettings"> 
      {{idprovider}} 
     </option>      
     </select>