Skip to content

Commit f3ae979

Browse files
committed
feat(asDirective): add support for the special case of ngForm controller named form
1 parent d470343 commit f3ae979

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/ng/directive/as.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ var componentAsDirective = ['$parse', function($parse) {
5151
var controllerName = tAttrs.$normalize(tElement[0].tagName.toLowerCase())
5252
.replace(/[^\w]\w/g, function(a) { return a.slice(1).toUpperCase(); });
5353

54+
// special case: ngForm is the only known directive that uses an undocumented
55+
// feature of .directive able to change the name of the directive
56+
if (controllerName === 'ngForm') {
57+
controllerName = 'form';
58+
}
59+
5460
// get the setter for the as attribute
5561
var setter = $parse(tAttrs.as).assign;
5662

test/ng/directive/asSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,10 @@ describe('as', function() {
124124
expect($rootScope.$ctrl.form.$valid).toBe(true);
125125
}));
126126

127+
it('should be compatible with ngForm', inject(function($compile, $rootScope) {
128+
$rootScope.$ctrl = {};
129+
$compile('<ng-form as="$ctrl.form"></ng-form>')($rootScope);
130+
expect($rootScope.$ctrl.form.$valid).toBe(true);
131+
}));
132+
127133
});

0 commit comments

Comments
 (0)