# Select model not bind in ion content

**URL:** <https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255>\
**Category:** ionic-v1\
**Created:** [July 23, 2014, 5:15pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255 "2014-07-23T17:15:09Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ho\_oh](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@ho\_oh](https://forum.ionicframework.com/u/ho_oh)\
**Post date:** [July 23, 2014, 5:15pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/1 "2014-07-23T17:15:11Z")

</div>

The problem occurs with the following ionic code:

```
<ion-content class="has-logo has-footer">
    <ion-item class='item-no-border'>
        <form>
            <span>{{prefGender.name}}</span>
            <!-- ng-select gender -->
            <select ng-model="prefGender" ng-options="gender.name for gender in preferences.gender">
            </select>

        </form>
    </ion-item>
</ion-content>

```

And the following is the controller data:

```
$scope.preferences = {gender: [{selected: true, name : "Man", value: 1}, {selected: true, name : "Woman", value: 2}]};
$scope.prefGender = $scope.preferences.gender[0];

```

When i select between option the ng-model ‘prefGender’ in the view work and _{{[prefGender.name](http://prefGender.name)}}_ change the value but inside the controller the ‘prefGender’ does not change and keep the initial value. The problem disappear when i remove all the ion tag (ion-view, ion-content, ion-item) in the html.

---

<div class="post-metadata">

**Author:** ![ho\_oh](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@ho\_oh](https://forum.ionicframework.com/u/ho_oh)\
**Post date:** [July 24, 2014, 4:12am UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/2 "2014-07-24T04:12:59Z")

</div>

Could anyone help me to solve this problem,please?

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 24, 2014, 2:46pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/3 "2014-07-24T14:46:57Z")

</div>

> [@ho\_oh](#):
>
> $scope.preferences = {gender: [{selected: true, name : “Man”, value: 1}, {selected: true, name : “Woman”, value: 2}]};  
> $scope.prefGender = $scope.preferences.gender[0];

Hey soo not sure what I should be looking at, seems to work for me.

https://codepen.io/mhartington/embed/preview/GDbJA?default-tabs=html%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=GDbJA

What part isn’t working exactly? Your description seems a bit vague.

---

<div class="post-metadata">

**Author:** ![ho\_oh](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@ho\_oh](https://forum.ionicframework.com/u/ho_oh)\
**Post date:** [July 25, 2014, 3:48am UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/4 "2014-07-25T03:48:27Z")

</div>

Yes it seem to work well from the view but inside the controller the model doesn’t change. You can check this [http://codepen.io/ho\_oh/pen/lrpeC](http://codepen.io/ho_oh/pen/lrpeC) . When click the check button the value keep the same.

So the problem is when access the model inside the controller it keeps the initial value, and it will work after remove the tag “ion-content”

---

<div class="post-metadata">

**Author:** ![ho\_oh](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@ho\_oh](https://forum.ionicframework.com/u/ho_oh)\
**Post date:** [July 25, 2014, 11:33am UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/5 "2014-07-25T11:33:43Z")

</div>

Is there any way to fix it or tricks to overcome this problem? Please help me!

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 25, 2014, 2:08pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/6 "2014-07-25T14:08:09Z")

</div>

Hmm, I think its the way you have the select set up, take a look at this example.

> **[Radio Buttons: 1.0.0-beta.9](https://codepen.io/mhartington/pen/azKiH)**
>
> Demo showing how to wire up radio buttons within Ionic. Forked from \[Ionic\](http://codepen.io/ionic/)'s Pen \[Radio Buttons: 1.0.0-beta.9\](http://codep...

Now the model updates correctly

---

<div class="post-metadata">

**Author:** ![ho\_oh](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@ho\_oh](https://forum.ionicframework.com/u/ho_oh)\
**Post date:** [July 25, 2014, 5:41pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/7 "2014-07-25T17:41:58Z")

</div>

I have found the trick to overcome this problem. Because the model change only in the view so i pass that changed value to controller through ng-change : [http://codepen.io/ho\_oh/pen/lrpeC](http://codepen.io/ho_oh/pen/lrpeC) .  
But i pretty sure that there is some problem with the ionic directive, i think it is not two way binding in this case because without ‘ion-content’ tag it works correctly (no need ng-change).

---

<div class="post-metadata">

**Author:** ![ho\_oh](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@ho\_oh](https://forum.ionicframework.com/u/ho_oh)\
**Post date:** [July 27, 2014, 6:46pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/8 "2014-07-27T18:46:29Z")

</div>

Please help me. Now i have the reversed problem, i want to change the selected option from the controller but the view only change for the first time [http://codepen.io/ho\_oh/pen/lrpeC](http://codepen.io/ho_oh/pen/lrpeC) . And one a again, it works correctly when remove the ‘ion-content’ tag ☹ . Is there any way to fix this problem completely?

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 28, 2014, 2:19pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/9 "2014-07-28T14:19:44Z")

</div>

Again, I think its the way you have yours set up.

> **[Radio Buttons: 1.0.0-beta.9](https://codepen.io/mhartington/pen/cxmyC)**
>
> Demo showing how to wire up radio buttons within Ionic. Forked from \[Ionic\](http://codepen.io/ionic/)'s Pen \[Radio Buttons: 1.0.0-beta.9\](http://codep...

---

<div class="post-metadata">

**Author:** ![ho\_oh](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@ho\_oh](https://forum.ionicframework.com/u/ho_oh)\
**Post date:** [July 28, 2014, 4:30pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/10 "2014-07-28T16:30:42Z")

</div>

I will try your way but i think my setup isn’t the problem because it is simple and follow exactly AngularJs instruction [https://docs.angularjs.org/api/ng/directive/select](https://docs.angularjs.org/api/ng/directive/select) . And i find out that not only the select menu but also other form elements get this issue, i also get this issue with the text input [http://codepen.io/ho\_oh/pen/ldEjg](http://codepen.io/ho_oh/pen/ldEjg)

---

<div class="post-metadata">

**Author:** ![ho\_oh](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@ho\_oh](https://forum.ionicframework.com/u/ho_oh)\
**Post date:** [July 28, 2014, 4:58pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/11 "2014-07-28T16:58:54Z")

</div>

Your solution just work with the simple model. In case of the more complex model it does not work [http://codepen.io/ho\_oh/pen/ijDzG](http://codepen.io/ho_oh/pen/ijDzG)

---

<div class="post-metadata">

**Author:** ![ThCodeDestroyer](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@ThCodeDestroyer](https://forum.ionicframework.com/u/ThCodeDestroyer)\
**Post date:** [July 30, 2014, 2:58pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/12 "2014-07-30T14:58:02Z")

</div>

I’m sorry your code is not complex, but its a mess,…  
I don’t know why you are using value prop as it seems you don’t use it anywhere.  
First of all I don’t get the Check function as it checks a hard coded value prop that never changes,  
you never set this `$scope.prefGender.value` the only thing that is changing is `$scope.prefGender.gender` so you should check that. Also I don’t get why are you even using values in the array as your `ng-value` attributes is using [gender.name](http://gender.name).

---

<div class="post-metadata">

**Author:** ![ThCodeDestroyer](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@ThCodeDestroyer](https://forum.ionicframework.com/u/ThCodeDestroyer)\
**Post date:** [July 31, 2014, 7:20am UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/13 "2014-07-31T07:20:00Z")

</div>

@ho_oh So I cleaned up mhartingtons example, how it should be, anyway you had issue with inherited scope this usually happens when there is another directive between your controller and select,input, etc. What you should usually do is declare variable inside another object so its more explicit.  
Check the example: [http://codepen.io/TheCodeDestroyer/pen/jnpLq](http://codepen.io/TheCodeDestroyer/pen/jnpLq)

---

<div class="post-metadata">

**Author:** ![ykpramodh](https://avatars.discourse-cdn.com/v4/letter/y/f04885/32.png) [@ykpramodh](https://forum.ionicframework.com/u/ykpramodh)\
**Post date:** [November 25, 2015, 1:17pm UTC](https://forum.ionicframework.com/t/select-model-not-bind-in-ion-content/7255/14 "2015-11-25T13:17:29Z")

</div>

@mhartington

Select behavior seems to have changed in Ionic. I tried directives from angular without success.

Your old example on codepen doesn’t seem to work. Can you please update based on your availability?
