Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chosen with AngularJs 1.3 #2159

Closed
willypowwow opened this issue Dec 6, 2014 · 3 comments
Closed

Chosen with AngularJs 1.3 #2159

willypowwow opened this issue Dec 6, 2014 · 3 comments

Comments

@willypowwow
Copy link

@willypowwow willypowwow commented Dec 6, 2014

I have been using Chosen for quite some time successfully with Angular 1.2 After having updated to AngularJS 1.2 I notice that the select box no longer displays an existing model value on page load though it will after selected an option from the list. Has anyone else reported this?

I have tried watching the model value from my directive but that has not helped

diligentApp.directive('rpdLookup', function () {

return {
    restrict: 'E',
    template: '<select ng-options="item.Value as item.Value for item in lookupList"><option value=""></Option></select>',
    controller: 'dropdownLookupCtrl',
    required: 'ngModel',
    replace: true,
    scope: {
        lookupList: '=',
        ngModel: '='
    },
    link: function (scope, element, attrs, modelCtrl) {

        if (!modelCtrl) return;

        element.chosen();

        var unwatch1 = scope.$watch('lookupList', function () {
            element.trigger('chosen:updated');
        });

        var unwatch2 = scope.$parent.$watch(attrs.ngDisabled, function (newVal) {
            element.prop('disabled', newVal);
            element.trigger('chosen:updated');
        });

        var unwatch3 = scope.$watch('ngModel', function () {
            element.trigger('chosen:updated');
        });

    }
}

});

@willypowwow
Copy link
Author

@willypowwow willypowwow commented Dec 6, 2014

I was able to resolve the problem by wrapping the trigger method within a $timeout. I have no idea why this behavior is different in AngularJs 1.3.

            scope.$watch('lookupList', function (newList, oldList) {
            $timeout(function () {
                element.trigger('chosen:updated');
            });
        });
@rodrigopires
Copy link

@rodrigopires rodrigopires commented Dec 9, 2014

Tks @willypowwow, I was with the same problem today and your tip helped me ;) Strange issue.

@pfiller
Copy link
Contributor

@pfiller pfiller commented Dec 23, 2014

Closed since @willypowwow was "able to resolve the problem"

@pfiller pfiller closed this Dec 23, 2014
pthorn added a commit to pthorn/angular-app-tools that referenced this issue Dec 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.