From 94dcb85737ebdf7c11ff29e71efcbdf7c66b0ded Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Tue, 29 Apr 2014 00:07:01 +0300 Subject: [PATCH] fix(ngModelOptions): add textarea support since directives are sorted by priority and name and `ngModel` & `textarea` have the same priority and 'textarea'>'ngModel' (unlike 'input'), textarea in linked first. this is a problem since textarea expect ngModelController.$options to exist and it is created only when ngModel is linked. this is solved easily by moving the creation of $options to pre-link. fixes #7281 --- src/ng/directive/input.js | 27 +++++++++++++++------------ test/ng/directive/inputSpec.js | 11 +++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 4a6a5827bd3c..32eac92b3ab3 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1973,22 +1973,25 @@ 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; + } + }, + post: function(scope, element, attr, ctrls) { + // notify others, especially parent forms - var modelCtrl = ctrls[0], - formCtrl = ctrls[1] || nullFormCtrl; + var modelCtrl = ctrls[0], + formCtrl = ctrls[1] || nullFormCtrl; - formCtrl.$addControl(modelCtrl); + formCtrl.$addControl(modelCtrl); - // Pass the ng-model-options to the ng-model controller - if ( ctrls[2] ) { - modelCtrl.$options = ctrls[2].$options; + 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( + '