0

I think the only way to do this is a service, but I would like to know if any other way is possible.

Parent:

<h1> Parent title </h1>
<child-element></childElement>

Child:

<form #f="ngForm">
    <mat-card-content>
      <mat-input-container>
        <input matInput [(ngModel)]="id" name="id" placeholder="ID"  #input/>
      </mat-input-container>
      <mat-input-container>
        <input matInput [(ngModel)]="name" name="name" placeholder="NAME"  #input/>
      </mat-input-container>
    </mat-card-content>
</form>

From child I can access with @ViewChildren:

export class ChildComponent implements OnInit {

    @ViewChildren('input') inputs;
   //rest of code
}

but it is possible access all of them in anyway from parent?

cucuru
  • 3,456
  • 8
  • 40
  • 74

1 Answers1

1

Not so clear, but if I get it :

<h1> Parent title </h1>
<child-element #child></childElement>

In your parent TS :

@ViewChild(ChildComponent) child: ChildComponent;

doSomething() {
  console.log(this.child.inputs);
}

This allows the parent to have access to the child as a Javascript object. Is this what you wanted ?