From fbf5ab8f17d28efeadb492c5a252f0778643f072 Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Tue, 29 Apr 2014 00:07:01 +0300 Subject: [PATCH] fix(ngModelOptions): initialize ngModelOptions in prelink Input controls require `ngModel` which in turn brings in the `ngModelOptions` but since ngModel does this initialization in the post link function, the order in which the directives are run is relevant. Directives are sorted by priority and name but `ngModel`, `input` and `textarea` have the same priority. It just happens that `textarea` is alphabetically sorted and so linked before `ngModel` (unlike `input`). This is a problem since inputs expect `ngModelController.$options` to exist at post-link time and for `textarea` this has not happened. This is solved easily by moving the initialization of `ngModel` to the pre-link function. Closes #7281 Closes #7292 --- src/ng/directive/input.js | 26 ++++++++++++++------------ test/ng/directive/inputSpec.js | 11 +++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index ff5ec4a194fc..6bc87b0e7899 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1973,22 +1973,24 @@ var ngModelDirective = function() { return { require: ['ngModel', '^?form', '^?ngModelOptions'], controller: NgModelController, - link: function(scope, element, attr, ctrls) { - // notify others, especially parent forms + link: { + pre: function(scope, element, attr, ctrls) { + // Pass the ng-model-options to the ng-model controller + if (ctrls[2]) { + ctrls[0].$options = ctrls[2].$options; + } - var modelCtrl = ctrls[0], - formCtrl = ctrls[1] || nullFormCtrl; + // notify others, especially parent forms - formCtrl.$addControl(modelCtrl); + var modelCtrl = ctrls[0], + formCtrl = ctrls[1] || nullFormCtrl; - // Pass the ng-model-options to the ng-model controller - if ( ctrls[2] ) { - modelCtrl.$options = ctrls[2].$options; - } + formCtrl.$addControl(modelCtrl); - scope.$on('$destroy', function() { - formCtrl.$removeControl(modelCtrl); - }); + scope.$on('$destroy', function() { + formCtrl.$removeControl(modelCtrl); + }); + } } }; }; diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index a87d3cc51261..43e99f0c6e63 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -642,6 +642,17 @@ describe('input', function() { expect(scope.name).toEqual('a'); }); + it('should allow overriding the model update trigger event on text areas', function() { + compileInput( + '