1

I have a modal component with this template:

  <div class="header"></div>
  <div class="body">
    <ng-content></ng-content>
  </div>
  <div class="footer">
    <button>Submit</button>
    <button>Cancel</button>
  </div>

In the ng content I pass with a service a template like this:

  <form  #contactForm="ngForm" (ngSubmit)="onSubmit()">
    /*some inputs */

    <button type="submit">Submit</button>
  </form>

I need to do a submit in my modal component on click on the button positioned on the footer section....I don't need the button inside the form (Must I hide it?) but I can't find a solution...How can I solve this situation?

1

1 Answer 1

2

template

<form #testForm="ngForm" (ngSubmit)="onSubmit(testForm)">
  <p>
    <label for="firstname">First Name</label>
    <input type="text" name="firstname" ngModel />
  </p>

  <p>
    <label for="lastname">Last Name</label>
    <input type="text" name="lastname" [(ngModel)]="lastname" />
  </p>

  <p>
    <button type="submit">Submit</button>
  </p>
</form>

<button (click)="save()">Submit</button>

ts code

export class HelloComponent {
  title = "Template driven forms";
  lastname = "patel";
  @ViewChild(NgForm) testForm: NgForm;
  
  onSubmit(contactForm) {
    console.log(contactForm.value);
  }
  save(e) {
    this.testForm.onSubmit(e);
  }
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.