最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - md-select not updating with ng-value text - Stack Overflow

matteradmin7PV0评论

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 ?

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 ?

Share Improve this question edited Aug 21, 2015 at 12:05 brouille asked Aug 21, 2015 at 10:37 brouillebrouille 3354 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

Post a comment

comment list (0)

  1. No comments so far