Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

md-select not updating with ng-value text

Hello i have a problem.

When i put an integer in ng-value, md-select is upadated:

<md-input-container>
      <md-select ng-model="test">
            <md-option ng-value="1">1</md-option>
            <md-option ng-value="2">2</md-option>
            <md-option ng-value="3">3</md-option>
            <md-option ng-value="4">4</md-option>
     </md-select>
</md-input-container>

But when i do this with string value it is not working, what can i do ?

<md-input-container>
   <md-select ng-model="type">
        <md-option ng-value=''></md-option>
        <md-option ng-value='test' >test</md-option>
        <md-option ng-value='test02'>test02</md-option>
        <md-option ng-value='test03' >test03</md-option>
   </md-select>
 </md-input-container>

What's wrong ?

like image 546
brouille Avatar asked Aug 21 '15 10:08

brouille


1 Answers

You can use value="" (expect a string)

This is working:

<md-input-container>
  <md-select ng-model="type">
    <md-option value=''></md-option>
    <md-option value='test' >test</md-option>
    <md-option value='test02'>test02</md-option>
    <md-option value='test03' >test03</md-option>
  </md-select>
</md-input-container>

Or you can use ng-value="" (expect an expression)

<md-input-container>    
  <md-select ng-model="type">
    <md-option ng-value="''"></md-option>
    <md-option ng-value="'test'" >test</md-option>
    <md-option ng-value="'test02'">test02</md-option>
    <md-option ng-value="'test03'" >test03</md-option>
  </md-select>
</md-input-container>

Your first example is working because integer values are correct expressions. In your second example angular is looking for a property named test in your scope.

like image 170
Christoph Avatar answered Oct 06 '22 10:10

Christoph