0

HTML

<select class = "box" ng-model="selected" ng-options="person.id as person.name for person in people" >
<option value="">----select----</option>
</select>

CSS

.box {
    height: 21px !important;
    width: 96%;
}

Hi, I'm updating the $scope.people and call $scope.$apply(... to update the dropdown. When I do this, the dropdown select box automatically increases the size and adjust the size according to my content. My content isn't even close to overflowing though. Would be great if I could get some help! In the link, $scope.people is statically defined since I wasn't able to demo the messaging service I'm using at the moment. I could just fix the width into a certain px size. But then when the browser window size is changed, the box size won't adjust according to that. Would be great to know if there's a way to fix this! Thanks :) http://jsfiddle.net/Lvc0u55v/7937/

Update I didn't mention this because I didn't know this would be the problem. This select box is in the table. It's within the <td></td> tag if that makes any difference..

6
  • what are you updating it with ? It will help a lot if you could create plunk. Commented Aug 4, 2016 at 11:08
  • @Alok I'm using a messaging service within the company. I'm updating the people with an array that has objects with properties, id and name. Commented Aug 4, 2016 at 11:12
  • could you give me a sample of JSON that you update it with? Commented Aug 4, 2016 at 11:17
  • @Alok At first, $scope.people is an empty list. And then something like above is provided. The box size changes when the content is populated. Commented Aug 4, 2016 at 11:24
  • Look at jsfiddle.net/4et7da1s/1 ... Should it have replicated your issue ?? Commented Aug 4, 2016 at 11:29

2 Answers 2

2

Please make sure you don't fix the height and width of the box and let bootstrap make it responsive on its own

Try this, it is working

<div class="container">
<div ng-controller="MyCtrl">
  <select class = "box" ng-model="selected" ng-options="person.id as person.name for person in people" >
    <option value="">----select----</option>
  </select>
</div>
</div>

and in css:

.box {
    height: auto;
    width: auto;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I just tried this but the select box increases its size, as soon as the $scope.people is updated.
0

I have created a fiddle http://jsfiddle.net/4et7da1s/2/

You can solve the problem with a mix of max-width and making the width as auto.

Something like this:

.box {
    height: 21px !important;
    width: auto;
    max-width: 20%;
}

Comments

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.