weird behavior scope and ng-repeat in view, angular JS

nacho c

I am having a weird behavior.

In the view I have the follow code :

<div class="form-group">

  <select class="form-control" name="name" id="repeatSelect" ng-model="selectedOption">
    <option ng-repeat="o in availableOptions" value="{{o}}">{{o.name}}</option>
      </select>
    </div>
<p>{{selectedOption}}</p>
<p>{{selectedOption.value}}</p>

And in the controller I have :

$scope.availableOptions= [
  {id: '1', name: 'name2', value:{w: 100, h: 250}},
  {id: '2', name: 'name1', value:{w: 200, h: 100}},
  ];
$scope.selectedOption = $scope.availableOptions[1];

The problem is the follow : At first time the first two <p> (selectedOption and selectedOption.value) are showing right. However when I change the value of in the select only <p>{{selectedOption}}</p> is showed while <p>{{selectedOption.value}}</p> doesn't show anything.

Any help???

PD: with ng-option into select it worked, but why with ng-repeat not?

Konkko

Only explanation I could think of was that it changes the object into a string. The work around you could do is creating ng-change="foo(selectedOption)" into the select and the function looking something like this:

$scope.foo = function(val){
     $scope.selectedOption = angular.fromJson(val);   
}

EDIT

http://www.w3schools.com/tags/tag_option.asp from here we can confirm that the value is converted to string.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Weird behavior of ng-repeat scope

From Dev

ng-repeat issue in angular js,$scope binding with the view

From Dev

Angular JS binding scope data within ng-repeat to form

From Dev

How to change the parent scope from ng-repeat individual scope - Angular JS

From Dev

Angular ng-transclude scope in repeat

From Dev

Angular ng-repeat causes isolated scope

From Dev

angular directive ng-repeat scope and Service

From Dev

Angular ng-transclude scope in repeat

From Dev

Weird scope behavior

From Dev

Weird Behavior: Angular Js - Spring Rest Service

From Dev

Angular js filter for ng repeat

From Dev

angular js ng-repeat a radio button list from scope with a default checked

From Dev

Angular.js scope variable undefined, ng-repeat initial state

From Dev

Ionic / Angular.js $scope is not passing the value without ng-repeat

From Dev

AngularJS: unable to access scope variable after ng-repeat in view

From Dev

view not updated after the ng-repeat looping array is updated in the scope

From Dev

angular ng-repeat dosen't wait for scope

From Dev

Modifying objects within Angular Scope inside ng-repeat

From Dev

Angular $compile on scope with ng-repeat doesn't work

From Dev

How to create a separate scope isolated from ng-repeat in Angular?

From Dev

Angular: scope, how to set ng-repeat in a Directive

From Dev

Angular $scope function not working outside of ng-repeat

From Dev

Angular $scope.model wont bind to ng-repeat

From Dev

Angular Directive scope binding not working in ng-repeat

From Dev

Angular $scope.model wont bind to ng-repeat

From Dev

Weird Angular controller behavior

From Dev

Angular JS Ng-Repeat Issue

From Dev

Angular JS: ng-repeat is not showing value

From Dev

Angular JS - ng-repeat and loop conditions

Related Related

  1. 1

    Weird behavior of ng-repeat scope

  2. 2

    ng-repeat issue in angular js,$scope binding with the view

  3. 3

    Angular JS binding scope data within ng-repeat to form

  4. 4

    How to change the parent scope from ng-repeat individual scope - Angular JS

  5. 5

    Angular ng-transclude scope in repeat

  6. 6

    Angular ng-repeat causes isolated scope

  7. 7

    angular directive ng-repeat scope and Service

  8. 8

    Angular ng-transclude scope in repeat

  9. 9

    Weird scope behavior

  10. 10

    Weird Behavior: Angular Js - Spring Rest Service

  11. 11

    Angular js filter for ng repeat

  12. 12

    angular js ng-repeat a radio button list from scope with a default checked

  13. 13

    Angular.js scope variable undefined, ng-repeat initial state

  14. 14

    Ionic / Angular.js $scope is not passing the value without ng-repeat

  15. 15

    AngularJS: unable to access scope variable after ng-repeat in view

  16. 16

    view not updated after the ng-repeat looping array is updated in the scope

  17. 17

    angular ng-repeat dosen't wait for scope

  18. 18

    Modifying objects within Angular Scope inside ng-repeat

  19. 19

    Angular $compile on scope with ng-repeat doesn't work

  20. 20

    How to create a separate scope isolated from ng-repeat in Angular?

  21. 21

    Angular: scope, how to set ng-repeat in a Directive

  22. 22

    Angular $scope function not working outside of ng-repeat

  23. 23

    Angular $scope.model wont bind to ng-repeat

  24. 24

    Angular Directive scope binding not working in ng-repeat

  25. 25

    Angular $scope.model wont bind to ng-repeat

  26. 26

    Weird Angular controller behavior

  27. 27

    Angular JS Ng-Repeat Issue

  28. 28

    Angular JS: ng-repeat is not showing value

  29. 29

    Angular JS - ng-repeat and loop conditions

HotTag

Archive