component.html
<div class="auth-wrapper">
<form class="form-signin" [formGroup]="signupForm" (ngSubmit)="registerUser()" >
<h3 class="h3 mb-3 font-weight-normal text-center">Please sign up</h3>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" formControlName="name" placeholder="Enter name" required>
</div>
<div class="form-group">
<label>Email address</label>
<input type="email" class="form-control" formControlName="email" placeholder="Enter email" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" formControlName="password" placeholder="Password" required>
</div>
<button type="submit" class="btn btn-block btn-primary">Sign up</button>
</form>
component.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from "@angular/forms";
import { AuthService } from './../../shared/auth.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-signup',
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.css']
})
export class SignupComponent implements OnInit {
signupForm: FormGroup;
constructor(
public fb: FormBuilder,
public authService: AuthService,
public router: Router
) {
this.signupForm = this.fb.group({
name: [''],
email: [''],
mobile: [''],
password: ['']
})
}
ngOnInit() { }
registerUser() {
this.authService.signUp(this.signupForm.value).subscribe((res) => {
if (res.result) {
this.signupForm.reset()
this.router.navigate(['log-in']);
}
})
}
}
En component.html, si cambio el ngSubmit por onsubmit y le pongo por ejemplo un alert('hola'), funciona, en cambio si pongo el alert con el ngSubmit, no hace nada, por lo tanto tampoco está haciendo el registerUser, he puesto alert en la función registerUser y tampoco lo hace, no está haciendo la función en absoluto