Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Update to Angular 1.4 breaks directives that manipulate ngOptions data #13145

Closed
realityking opened this issue Oct 21, 2015 · 5 comments
Closed

Comments

@realityking
Copy link
Contributor

I think there's some subtle difference in the way scopes work between 1.3 and 1.4, but I couldn't find anything in the changelogs.

In 1.3 we use a directive like the following to add data to a select element. We don't put the entire element into the directive, as that breaks the for attribute, it's also not that easy to handle with ngModel.

module.directive('selectCountry', function () {
        return {
            restrict: 'A',
            scope: true,
            link: function ($scope, elem, attrs) {
                attrs.ngOptions = 'country.code as country.name for country in countryList | orderBy:"name"';
            },
            controller: function ($scope, countryList) {
                $scope.countryList = [];

                countryList.getList()
                    .then(function(result) {
                        $scope.countryList = result;
                    });
            }
        };
    })

Plunkr: http://embed.plnkr.co/COWqvLE14hFHnioHn9dP/preview

@akhileshtiwari123
Copy link

Hi All

Please Remove my Email from Group

Thanks
Akhilesh

On 10/21/2015 7:41 PM, Rouven Weßling wrote:

I think there's some subtle difference in the way scopes work between
1.3 and 1.4, but I couldn't find anything in the changelogs.

In 1.3 we use a directive like the following to add data to a select
element. We don't put the entire element into the directive, as that
breaks the |for| attribute, it's also not that easy to handle with
ngModel.

module.directive('selectCountry',function () {
return {
restrict: 'A',
scope: true,
link: function ($scope,elem,attrs) {
attrs.ngOptions= 'country.code as country.name for country in countryList | orderBy:"name"';
},
controller: function ($scope,countryList) {
$scope.countryList= [];

             countryList.getList()
                 .then(function(result) {
                     $scope.countryList=  result;
                 });
         }
     };
 })

Plunkr: http://embed.plnkr.co/COWqvLE14hFHnioHn9dP/preview


Reply to this email directly or view it on GitHub
#13145.

Thanks & Regards
Akhilesh Tiwari
Sr. Developer
Dept:- .Net Development


Cyber Infrastructure (P) Limited, [CIS] *(CMMI Level 3 Certified)*

Central India's largest IT Services company.

Ensuring the success of our clients and partners through our highly
optimized IT solutions.

www.cisin.com | +Cisin https://plus.google.com/+Cisin/ | Linkedin
https://www.linkedin.com/company/cyber-infrastructure-private-limited |
Offices: Indore, India. Singapore. Silicon Valley, USA.

DISCLAIMER: INFORMATION PRIVACY is important for us, If you are not the
intended recipient, you should delete this message and are notified that
any disclosure, copying or distribution of this message, or taking any
action based on it, is strictly prohibited by Law.

@Narretz
Copy link
Contributor

Narretz commented Oct 27, 2015

@realityking This is because the whole ngOptions logic is now inside a new directive, which means adding the attribute doesn't trigger the behavior anymore. I think this is missing from the changelog. I'm afraid this kind of manipulation simply doesn't work anymore.

@akhileshtiwari123 It's possible that you are watching the angular repo. If so, please go to the repo and remove yourself.

@Narretz Narretz added this to the Backlog milestone Oct 27, 2015
@dustinhorne
Copy link

We are running into an issue with ngOptions in a directive as well but haven't narrowed it down. We have a directive that outputs "controls" using an ngRepeat. Each control has it's own isolated scope. Everything works fine, except dropdowns using ngOptions. The values are repeated. They only exist once in the scope value, but they are output twice by Angular, and the objectid's are duplicated as well so they point to the same instance. It doesn't break binding to the ng-model but it makes the values show up duplicate in the dropdown.

@gkalpak
Copy link
Member

gkalpak commented Nov 5, 2015

@dustinhorne, your problem sounds like a duplicate fo #12190 (comment) and must have been already fixed in master with 53cb88a.
(You can test it with https://code.angularjs.org/snapshot/angular.js.)

@dustinhorne
Copy link

@gkalpak - Thank you much, I'll give it a shot! We had just updated a couple of weeks ago so I didn't figure it would have been fixed. It looks like exactly my issue because dropdowns in my views work fine, but dropdowns within directives that are compiled with the values present do result in the duplication.

Confirmed, that snapshot fixed the problem. Thanks again!

@Narretz Narretz closed this as completed in 077ee37 Nov 6, 2015
Narretz added a commit that referenced this issue Nov 6, 2015
gkalpak pushed a commit to gkalpak/angular.js that referenced this issue Nov 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants
@realityking @Narretz @dustinhorne @akhileshtiwari123 @gkalpak and others