0
How to get feedback from the post through the Component?
Code:
service
import {Injectable} from '@angular/core'
import {HttpClient,HttpHeaders} from '@angular/common/http'
import {Observable} from 'rxjs/Observable'
import 'rxjs/add/operator/map'
import { error } from 'selenium-webdriver';
@Injectable()
export class AppService{
constructor(private http:HttpClient){}
sendEmail(email){
return this.http.post('http://localhost:8080/backendteste/db/email.php?acao=sendEmail',email)
.subscribe((data)=>{
console.log('pegando retorno do backend ',data);
},(error)=>{
console.log('ERROR: ',error);
});
}
clear(){
return true;
}
}
Component
export class AppComponent implements OnInit {
statusEmail:string;
constructor(private fb: FormBuilder, private appService: AppService) { }
enviarEmail(form){
this.appService.sendEmail(form);
// console.log(form);
}
}
html
<div class="" *ngIf="statusEmail">
<i class="rounded-x fa fa-check"></i>
<p>Sua mensagem foi enviada com sucesso !</p>
</div>
If you have no problem reading in English you have a great explanation here about http responses using https://scotch.io/tutorials/angular-2-http-requests-with-observables
– Rômulo Gabriel Rodrigues
@Herick what is the return of the post?
– mercador