How to get the postback 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>