edite la pregunta, porque genere un nuevo proyecto angular y copie este codigo para enviar el formulario. Los errores que me da son 4
ngForm Error: contact/contact.component.ts:48:38 - error TS2304: Cannot find name 'NgForm'.
48 getSentServices(body:ContactForm, f: NgForm){
no me deja declarar el componente app-contacta en App Module ni en app.component Error: app.module.ts:10:5 - error NG6001: The class 'ContactComponent' is listed in the declarations of the NgModule 'AppModule', but is not a directive, a component, or a pipe. Either remove it from the NgModule's declarations, or add an appropriate Angular decorator.
10 ContactComponent ~~~~~~~~~~~~~~~~
contact/contact.component.ts:31:14 31 export class ContactComponent implements OnInit { ~~~~~~~~~~~~~~~~ 'ContactComponent' is declared here.
y con matsnackbar
contact/contact.component.ts:39:72 39 constructor(private sendServices: SendEmailService, public snackBar: MatSnackBar) { } ~~~~~~~~~~~ This type does not have a value, so it cannot be used as injection token.
contact/contact.component.ts
import { Component, OnInit } from '@angular/core';
//componentes de form
import {FormControl, NgForm, Validators} from '@angular/forms';
//modelo creado
import {ContactForm} from '../models/contactForm';
//services en angular
import {SendEmailService} from '../services/send-email.service';
//libreria rxjs
//libreria rxjs
import { Observable } from 'rxjs';
import { of } from 'rxjs';
//material desing de angular
import {MatSnackBar} from '@angular/material/snack-bar';
@Component({
selector: 'app-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.css']
})
export class ContactComponent implements OnInit {
//creacion de variable contact
ContactModel = new ContactForm();
private emailResponse: any;
private truefalse:boolean = false;
constructor(private sendServices: SendEmailService, public snackBar: MatSnackBar) { }
ngOnInit() {
}
onSubmit(f: NgForm){
this.getSentServices(this.ContactModel, f);
}
//metodo de services
getSentServices(body:ContactForm, f: NgForm){
this.sendServices.getResponseEmail(body).subscribe(
data => {
if(data){
this.snackBar.open("Gracias por el mensaje", "Correcto", {
duration: 2000,
});
f.reset();
}
else{
this.snackBar.open(":(", "Error", {
duration: 2000,
});
}
},
err => { this.snackBar.open("Algo fallo :/, correo: cesar@unprogramador.com", "ups", {
duration: 5000,
}); }
);
}
}
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ContactComponent } from './contact/contact.component';
@NgModule({
declarations: [
AppComponent,
ContactComponent --me la rechaza--
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule { }