Skip to content

Instantly share code, notes, and snippets.

@hotienvu
Last active December 14, 2015 15:08
Show Gist options
  • Save hotienvu/5105501 to your computer and use it in GitHub Desktop.
Save hotienvu/5105501 to your computer and use it in GitHub Desktop.
My custom directive to 2 way-bind the size attribute of <select>. The issue is open here https://github.com/angular/angular.js/issues/1619
myApp.directive('ngSize', function() {
return {
restrict:'A',
scope: {
ngSize: '='
},
link: function(scope, elem, attrs) {
scope.$watch("ngSize", function(newVal, oldVal) {
angular.element(elem).attr('size', newVal);
});
}
};
});
@mlegenhausen
Copy link

Using an isolated scope does not work when using ng-options. Use this instead:

link: function(scope, elem, attrs) {
            scope.$watch(attrs['ngSize'], function(size) {
                angular.element(elem).attr('size', size);
            });
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment