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

Commit ded2518

Browse files
committed
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.
1 parent b366f03 commit ded2518

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/ng/directive/ngOptions.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,11 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
395395
return {
396396
restrict: 'A',
397397
terminal: true,
398-
require: ['select', '?ngModel'],
398+
require: ['select', 'ngModel'],
399399
link: function(scope, selectElement, attr, ctrls) {
400400

401-
// if ngModel is not defined, we don't need to do anything
402-
var ngModelCtrl = ctrls[1];
403-
if (!ngModelCtrl) return;
404-
405401
var selectCtrl = ctrls[0];
402+
var ngModelCtrl = ctrls[1];
406403
var multiple = attr.multiple;
407404

408405
// The emptyOption allows the application developer to provide their own custom "empty"

test/ng/directive/ngOptionsSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ describe('ngOptions', function() {
156156
});
157157

158158

159-
it('should have optional dependency on ngModel', function() {
159+
it('should have a dependency on ngModel', function() {
160160
expect(function() {
161161
compile('<select ng-options="item in items"></select>');
162-
}).not.toThrow();
162+
}).toThrow();
163163
});
164164

165165

0 commit comments

Comments
 (0)