From ff231a943779657b731e971530c068be799ffde9 Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Mon, 14 Sep 2015 11:12:44 +0200 Subject: [PATCH] fix(ngOptions): throw if ngModel is not present Closes #7047 Closes #12840 BREAKING CHANGE: `ngOptions` will now throw if `ngModel` is not present on the `select` element. Previously, having no `ngModel` let `ngOptions` silently fail, which could lead to hard to debug errors. The change should therefore not affect any applications, as it simply makes the requirement more strict and alerts the developer explicitly. --- src/ng/directive/ngOptions.js | 7 ++----- test/ng/directive/ngOptionsSpec.js | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ng/directive/ngOptions.js b/src/ng/directive/ngOptions.js index e07aa137f2a6..acdb9648f51a 100644 --- a/src/ng/directive/ngOptions.js +++ b/src/ng/directive/ngOptions.js @@ -395,14 +395,11 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) { return { restrict: 'A', terminal: true, - require: ['select', '?ngModel'], + require: ['select', 'ngModel'], link: function(scope, selectElement, attr, ctrls) { - // if ngModel is not defined, we don't need to do anything - var ngModelCtrl = ctrls[1]; - if (!ngModelCtrl) return; - var selectCtrl = ctrls[0]; + var ngModelCtrl = ctrls[1]; var multiple = attr.multiple; // The emptyOption allows the application developer to provide their own custom "empty" diff --git a/test/ng/directive/ngOptionsSpec.js b/test/ng/directive/ngOptionsSpec.js index 40cb245253d5..f66a56df034c 100644 --- a/test/ng/directive/ngOptionsSpec.js +++ b/test/ng/directive/ngOptionsSpec.js @@ -156,10 +156,10 @@ describe('ngOptions', function() { }); - it('should have optional dependency on ngModel', function() { + it('should have a dependency on ngModel', function() { expect(function() { compile(''); - }).not.toThrow(); + }).toThrow(); });