Last active
May 13, 2019 11:51
-
-
Save navix/8a56e4eec7cb2ec4a0eacc0c58ae3fd4 to your computer and use it in GitHub Desktop.
Revisions
-
navix revised this gist
May 13, 2019 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,8 +35,4 @@ Use it in a child component: * Parent component should have `<form>` element. Child components should be inside of that element. * Each `ngModel` should have unique `name` (can be an issue in cycles). * There is alternative method with `viewProviders` instead a directive: https://medium.com/@a.yurich.zuev/angular-nested-template-driven-form-4a3de2042475 -
navix revised this gist
May 13, 2019 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,13 @@ Use it in a child component: </ng-container> ``` ### Be aware * Parent component should have `<form>` element. Child components should be inside of that element. * Each `ngModel` should have unique `name` (can be an issue in cycles). ### Alternative method with `viewProviders` instead a directive https://medium.com/@a.yurich.zuev/angular-nested-template-driven-form-4a3de2042475 -
navix revised this gist
May 13, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ export class FormProviderDirective { Use it in a child component: ```html <ng-container formProvider> <input name="inChild" [(ngModel)]="form.inChild"> </ng-container> ``` -
navix revised this gist
May 13, 2019 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,4 +28,9 @@ Use it in a child component: <ng-container appFormProvider> <input name="inChild" [(ngModel)]="form.inChild"> </ng-container> ``` ### Be aware * Parent component should have `<form>` element. Child components should be inside of that element. * Each `ngModel` should have unique `name` (can be an issue in cycles). -
navix revised this gist
May 13, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Bind ngModel controls to ngForm from parent component This allows you to split a template-driven form on components. Create `formProvider` directive to proxy `ngModel` injector from parent to child: -
navix revised this gist
May 13, 2019 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ # Bind ngModel controls to ngForm from parent component This allows you to split form on components. Create `formProvider` directive to proxy `ngModel` injector from parent to child: ```typescript import { Directive, SkipSelf, forwardRef } from '@angular/core'; -
navix revised this gist
May 13, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ export class FormProviderDirective { Use it in a child component: ```html <ng-container appFormProvider> <input name="inChild" [(ngModel)]="form.inChild"> </ng-container> ``` -
navix created this gist
May 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ # Bind ngModel controls to ngForm from parent component Create `formProvider` directive to proxy `ngModel` injector from parent to child. ```typescript import { Directive, SkipSelf, forwardRef } from '@angular/core'; import { ControlContainer, Form } from '@angular/forms'; @Directive({ selector: '[formProvider]', providers: [ { provide: ControlContainer, useFactory: (parent) => parent, deps: [[new SkipSelf(), ControlContainer]], } ] }) export class FormProviderDirective { } ``` Use it in a child component: ```html <div appFormProvider> <input name="inChild" [(ngModel)]="form.inChild"> </div> ```