Boa tarde,
Venho por meio desse fórum ajuda pra verificar um erro que estou tendo em relação a uma página que estou fazendo;
Uma página está com "error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with runInInjectionContext
."
como ná imagem abaixo
Meu auth.service.ts:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Account } from '../account.model';
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(private http: HttpClient){}
apiURL= 'http://localhost:3000/contas/signup';
logAccount(){
return this.http.get(this.apiURL);
}
registerAccount(account: Account){
return this.http.post(this.apiURL, account);
}
}
E o component responsavel pela pagina de cadastro:
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { Account } from '../../services/account.model';
import { Router } from '@angular/router';
import { AuthService } from 'src/app/services/services/auth.service';
@Component({
selector: 'app-new-account',
templateUrl: './new-account.component.html',
styleUrls: ['./new-account.component.css']
})
export class NewAccountComponent implements OnInit{
public registerForm: FormGroup = new FormGroup({
'fullName': new FormControl('', Validators.minLength(5)),
'email': new FormControl('', Validators.email),
'CPF': new FormControl('', Validators.maxLength(11)),
'date': new FormControl('', Validators.required),
'password': new FormControl('', Validators.maxLength(6)),
})
constructor( private auth: AuthService,
private toastr: ToastrService,
private router: Router){}
ngOnInit() {
}
public registerAccount(): void{
let newAccount: Account = new Account(
this.registerForm.value.fullName,
this.registerForm.value.email,
this.registerForm.value.CPF,
this.registerForm.value.date,
this.registerForm.value.password,
)
this.auth.registerAccount(newAccount);{
if(this.registerForm.valid){
this.auth.registerAccount(this.registerForm.value).subscribe(res=>{
this.toastr.success('Cadastrado com sucesso');
this.router.navigate(['login']);
});
}else{
this.toastr.warning('Por favor insira os dados corretos')
}
}
}
}
Estou batendo a cabeça um cota e já não seu o que fazer, agradeço a atenção adiantada;