From 8ea802a1d23ad8ecacab892a3a451a308d9c39d7 Mon Sep 17 00:00:00 2001 From: Matthew Windwer Date: Tue, 2 Jul 2013 15:14:24 -0400 Subject: feat(ngForm): Supports expression in form names
form controller will accessible as $scope.ctrl.form instead of $scope['ctrl.form'] BREAKING CHANGE: If you have form names that will evaluate as an expression: And if you are accessing the form from your controller: Before: function($scope) { $scope['ctrl.form'] // form controller instance } After: function($scope) { $scope.ctrl.form // form controller instance } This makes it possible to access a form from a controller using the new "controller as" syntax. Supporting the previous behavior offers no benefit. --- test/ng/directive/formSpec.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js index b3673264..fb64fdb3 100644 --- a/test/ng/directive/formSpec.js +++ b/test/ng/directive/formSpec.js @@ -83,10 +83,11 @@ describe('form', function() { }); - it('should allow form name to be an expression', function() { + it('should support expression in form name', function() { doc = $compile('
')(scope); - expect(scope['obj.myForm']).toBeTruthy(); + expect(scope.obj).toBeDefined(); + expect(scope.obj.myForm).toBeTruthy(); }); @@ -325,6 +326,30 @@ describe('form', function() { }); + it('should deregister a child form whose name is an expression when its DOM is removed', function() { + doc = jqLite( + '
' + + '
' + + '' + + '
' + + '
'); + $compile(doc)(scope); + scope.$apply(); + + var parent = scope.parent, + child = scope.child.form; + + expect(parent).toBeDefined(); + expect(child).toBeDefined(); + expect(parent.$error.required).toEqual([child]); + doc.children().remove(); //remove child + + expect(parent.child).toBeUndefined(); + expect(scope.child.form).toBeUndefined(); + expect(parent.$error.required).toBe(false); + }); + + it('should deregister a input when its removed from DOM', function() { doc = jqLite( '
' + -- cgit v1.2.3