From 6bef1c4169415554f31a572958f79a7ad845560c Mon Sep 17 00:00:00 2001 From: vsavkin Date: Mon, 1 Jun 2015 13:11:34 -0700 Subject: [PATCH] feat(forms): changed the selector of TemplatdrivenFormDirective to match
--- .../template_driven_form_directive.ts | 5 +++- .../angular2/test/forms/integration_spec.ts | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/modules/angular2/src/forms/directives/template_driven_form_directive.ts b/modules/angular2/src/forms/directives/template_driven_form_directive.ts index b601fb6313..fb39da64cb 100644 --- a/modules/angular2/src/forms/directives/template_driven_form_directive.ts +++ b/modules/angular2/src/forms/directives/template_driven_form_directive.ts @@ -13,7 +13,10 @@ import {setUpControl} from './shared'; const formDirectiveBinding = CONST_EXPR(new Binding( ControlContainerDirective, {toAlias: FORWARD_REF(() => TemplateDrivenFormDirective)})); -@Directive({selector: '[form]', hostInjector: [formDirectiveBinding]}) +@Directive({ + selector: 'form:not([ng-no-form]):not([form-model]),ng-form,[ng-form]', + hostInjector: [formDirectiveBinding] +}) export class TemplateDrivenFormDirective extends ControlContainerDirective implements FormDirective { form: ControlGroup; diff --git a/modules/angular2/test/forms/integration_spec.ts b/modules/angular2/test/forms/integration_spec.ts index 4798c79bdf..bee7092718 100644 --- a/modules/angular2/test/forms/integration_spec.ts +++ b/modules/angular2/test/forms/integration_spec.ts @@ -427,11 +427,11 @@ export function main() { inject([TestBed], fakeAsync(tb => { var ctx = MyComp.create({name: null}); - var t = `
+ var t = `
-
`; +
`; tb.createView(MyComp, {context: ctx, html: t}) .then((view) => { @@ -448,14 +448,30 @@ export function main() { flushMicrotasks(); }))); + it("should not create a template-driven form when ng-no-form is used", + inject([TestBed], fakeAsync(tb => { + var ctx = MyComp.create({name: null}); + + var t = `
+
`; + + tb.createView(MyComp, {context: ctx, html: t}) + .then((view) => { + view.detectChanges(); + + expect(view.rawView.elementInjectors.length).toEqual(0); + }); + flushMicrotasks(); + }))); + it("should remove controls", inject([TestBed], fakeAsync(tb => { var ctx = MyComp.create({name: 'show'}); - var t = `
+ var t = `
-
`; + `; tb.createView(MyComp, {context: ctx, html: t}) .then((view) => { @@ -481,11 +497,11 @@ export function main() { var ctx = MyComp.create({name: 'show'}); - var t = `
+ var t = `
-
`; + `; tb.createView(MyComp, {context: ctx, html: t})