Skip to content

Instantly share code, notes, and snippets.

@navix
Last active May 13, 2019 11:51
Show Gist options
  • Save navix/8a56e4eec7cb2ec4a0eacc0c58ae3fd4 to your computer and use it in GitHub Desktop.
Save navix/8a56e4eec7cb2ec4a0eacc0c58ae3fd4 to your computer and use it in GitHub Desktop.

Revisions

  1. navix revised this gist May 13, 2019. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions README.md
    Original 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).


    ### Alternative method with `viewProviders` instead a directive

    https://medium.com/@a.yurich.zuev/angular-nested-template-driven-form-4a3de2042475
    * There is alternative method with `viewProviders` instead a directive: https://medium.com/@a.yurich.zuev/angular-nested-template-driven-form-4a3de2042475
  2. navix revised this gist May 13, 2019. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion README.md
    Original 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).
    * 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
  3. navix revised this gist May 13, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original 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 appFormProvider>
    <ng-container formProvider>
    <input name="inChild" [(ngModel)]="form.inChild">
    </ng-container>
    ```
  4. navix revised this gist May 13, 2019. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion README.md
    Original 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).
  5. navix revised this gist May 13, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original 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 form on components.
    This allows you to split a template-driven form on components.

    Create `formProvider` directive to proxy `ngModel` injector from parent to child:

  6. navix revised this gist May 13, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # Bind ngModel controls to ngForm from parent component

    Create `formProvider` directive to proxy `ngModel` injector from parent to child.
    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';
  7. navix revised this gist May 13, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ export class FormProviderDirective {
    Use it in a child component:

    ```html
    <div appFormProvider>
    <ng-container appFormProvider>
    <input name="inChild" [(ngModel)]="form.inChild">
    </div>
    </ng-container>
    ```
  8. navix created this gist May 13, 2019.
    29 changes: 29 additions & 0 deletions README.md
    Original 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>
    ```