4

My HTML code:

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

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

I want to prefill my ui-select input. I am using ui-select. If i don't use ui-select input and just use tags, then its working. But, not with tags.

What are the possible solutions? Please help me out as i have used in my application.

2 Answers 2

3

just set lenderInfo.modelState.selected with the value you want preselected.

here is some code for you to try just throw these lines where you setup the controller

$scope.lenderInfo.modelState = {};
$scope.lenderInfo.modelState.selected =  {"stateId":1,"stateName":"Florida"};
Sign up to request clarification or add additional context in comments.

Comments

0

You need to have the state you want prefilledto be available in the states array. If that doesn't fix it, make a plunker/fiddle and I'll look into it :)

1 Comment

This should be a comment and not an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.