diff --git a/src/ng/directive/ngModel.js b/src/ng/directive/ngModel.js index 44cfdbddabfe..028208cf1026 100644 --- a/src/ng/directive/ngModel.js +++ b/src/ng/directive/ngModel.js @@ -1215,7 +1215,7 @@ var ngModelOptionsDirective = function() { restrict: 'A', controller: ['$scope', '$attrs', function($scope, $attrs) { var that = this; - this.$options = $scope.$eval($attrs.ngModelOptions); + this.$options = angular.copy($scope.$eval($attrs.ngModelOptions)); // Allow adding/overriding bound events if (this.$options.updateOn !== undefined) { this.$options.updateOnDefault = false; diff --git a/test/ng/directive/ngModelSpec.js b/test/ng/directive/ngModelSpec.js index dfa20a75dd0f..583414deaa9c 100644 --- a/test/ng/directive/ngModelSpec.js +++ b/test/ng/directive/ngModelSpec.js @@ -1733,6 +1733,34 @@ describe('ngModelOptions attributes', function() { }); + it('should allow sharing options between multiple inputs', function() { + $rootScope.options = {updateOn: 'default'}; + var inputElm = helper.compileInput( + '' + + ''); + + helper.changeGivenInputTo(inputElm.eq(0), 'a'); + helper.changeGivenInputTo(inputElm.eq(1), 'b'); + expect($rootScope.name1).toEqual('a'); + expect($rootScope.name2).toEqual('b'); + }); + + + it('should hold a copy of the options object', function() { + $rootScope.options = {updateOn: 'default'}; + var inputElm = helper.compileInput( + ''); + expect($rootScope.options).toEqual({updateOn: 'default'}); + expect($rootScope.form.alias.$options).not.toBe($rootScope.options); + }); + + it('should allow overriding the model update trigger event on checkboxes', function() { var inputElm = helper.compileInput( '