r/javascript • • Feb 05 '16

Angular 1.5.0 has been released

http://angularjs.blogspot.com/2016/02/angular-150-ennoblement-facilitation.html
96 Upvotes

20 comments sorted by

View all comments

2

u/campbeln Feb 05 '16 edited Feb 05 '16

Have they fixed the issue with ng-options/select's ng-models value comparisons? A change with 1.4+ was to always have:

<option value="2">Two</option>

be === "2" as all underlying values are strings (fair enough) rather than == 2 as per <1.4. The problem is none of our non-string bound selects are binding anymore because 2 !== "2".

From == to === is a good change, but it seems the Angular team hasn't bothered to coerce the left-hand side of the expression into a string but has left that on us as devs to do it?! Really? So I have to change ALL of my APIs rather than the Angular team adding value + '' on the left?

I'm working on a major Australian government system that uses Angular and we are unable to upgrade past 1.3 currently because of this problem. Or have we managed to miss an easy fix for this issue?

Here's an extremely simplified example of the issue we're experiencing:

<script>
    $scope.data = { age: 2 };
<script>

<select ng-model="data.age">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
</select>

Angular 1.3 binds the select without issue, while 1.4+ does 2 === "2" et'al and of course doesn't find a match and leaves the select as blank. How have the rest of you guys fixed this in 1.4+?

0

u/[deleted] Feb 05 '16

[deleted]

1

u/campbeln Feb 06 '16

But you can't do this if you're doing something stupid like returning a new object from a function call (e.g. ng-options='item in myFunct()'). Then you try and use track by but that cannot be used with selects (as in the horrible ng-options version, not HTML DOM objects). What may* get us around it is to cache the results from the first call so that all references are the same and we won't need track by, but I'm not sure that will work in all cases in our system.

1

u/treetimes Feb 06 '16

You could always make your function act on a persistent scope reference rather than create a new object.