Set ng-selected to angular -ui select

My HTML is:

<div class="form-group col-md-4">
      <label for="lenderBusinessState">Select State</label>
      <div class="input-group select2-bootstrap-append">

        <ui-select name="lenderBusinessState" ng-model="lenderInfo.modelState.selected" theme="select2" class="form-control">
          <match placeholder="Select Lender State">{{$select.selected.stateName}}</match>
          <choices repeat="state in states | filter: $select.search">
            <span ng-bind-html="state.stateName | highlight: $select.search" ng-selected="selectState(state.stateId)"></span>
          </choices>
        </ui-select>

        <span class="input-group-btn">
          <button type="button" ng-click="lenderInfo.modelState.selected = undefined" class="btn btn-danger">
            <span class="glyphicon glyphicon-trash"></span>
          </button>
        </span>
      </div>
    </div>

My JS code is:

$scope.selectState = function(stateIdPassed)
{
    console.log(stateIdPassed);
    if(stateIdPassed == $scope.stateId){
        return 'selected';
    }
}

I want to pre-populate my ui-select input. I am using ui-select . If I do not use the ui-select input and just use tags, then its working. But not with tags.

What are the possible solutions? Please help me as I used in my application.

+4
source share
2 answers

just set lenderInfo.modelState.selected with the value you want to pre-select.

here is some code for you, try just throwing these lines where you configure the controller

$scope.lenderInfo.modelState = {};
$scope.lenderInfo.modelState.selected =  {"stateId":1,"stateName":"Florida"};
+3
source

, , . , /, :)

0

Source: https://habr.com/ru/post/1535739/


All Articles