diff options
| author | Vojta Jina | 2012-03-08 15:03:24 -0800 |
|---|---|---|
| committer | Vojta Jina | 2012-03-09 10:10:28 -0800 |
| commit | e0c9551fd7c716d9d71ed6f4f1d2f5911f53032c (patch) | |
| tree | f98632d66538460b1405d217342f483de6d519df /src/directive/form.js | |
| parent | fae84463e45f18eabdabc4c1c7378e23ad35842c (diff) | |
| download | angular.js-e0c9551fd7c716d9d71ed6f4f1d2f5911f53032c.tar.bz2 | |
refactor(forms): remove registerWidget and use event instead
Each widget (ng-model directive) emits $newFormControl event instead of getting hold of parent form
and calling form.registerWidget(this);
Diffstat (limited to 'src/directive/form.js')
| -rw-r--r-- | src/directive/form.js | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/directive/form.js b/src/directive/form.js index c3e6b21d..e3b937da 100644 --- a/src/directive/form.js +++ b/src/directive/form.js @@ -33,7 +33,7 @@ function FormController($scope, name) { $scope.$on('$destroy', function(event, widget) { if (!widget) return; - if (widget.widgetId) { + if (widget.widgetId && form[widget.widgetId] === widget) { delete form[widget.widgetId]; } forEach(errors, removeWidget, widget); @@ -60,6 +60,12 @@ function FormController($scope, name) { form.pristine = false; }); + $scope.$on('$newFormControl', function(event, widget) { + if (widget.widgetId && !form.hasOwnProperty(widget.widgetId)) { + form[widget.widgetId] = widget; + } + }); + // init state form.dirty = false; form.pristine = true; @@ -95,26 +101,6 @@ function FormController($scope, name) { } } -/** - * @ngdoc function - * @name angular.module.ng.$compileProvider.directive.form.FormController#registerWidget - * @methodOf angular.module.ng.$compileProvider.directive.form.FormController - * @function - * - * @param {Object} widget Widget to register (controller of a widget) - * @param {string=} alias Name alias of the widget. - * (If specified, widget will be accesible as a form property) - * - * @description - * - */ -FormController.prototype.registerWidget = function(widget, alias) { - if (alias && !this.hasOwnProperty(alias)) { - widget.widgetId = alias; - this[alias] = widget; - } -}; - /** * @ngdoc directive |
