ng-repeat vs ng-options which is best for me

后端 未结 3 1348
闹比i
闹比i 2021-01-14 12:42

i have to display the JSON data in drop down list ,for that i have two options one of the options is By using ng-repeat and other one is ng-options.

ng-repeat code :

3条回答
  •  孤城傲影
    2021-01-14 13:14

    The code below (also in Plunker) shows no difference even when the model is bound to a non-string value (an arithmetic code) except for the initialization where the approach with ng-repeat fails to display the default value (or maybe there's a workaround for that as well). After a value is chosen the behavior is the same:

    
      
        making choices 
        
      
      
        
    Select your favorite fruit:
    Selected fruit is: {{ctl.getSelectedFruit().label}} (from code: {{ctl.selectedFruitCode}})

    Select your favorite fruit:
    Selected fruit is: {{ctl.getSelectedFruit().label}} (from code: {{ctl.selectedFruitCode}})

提交回复
热议问题