Monday, August 19, 2019

Post in ionic 4 or 5 with api with fromUri

1. Post in ionic 4 or 5 with api with fromUri




Code is ...


import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';

@Component({
selector: 'app-create2',
templateUrl: './create2.page.html',
styleUrls: ['./create2.page.scss'],
})
export class Create2Page implements OnInit {

result: any= [];
data: Observable<any>;

constructor(private http: HttpClient) { }

ngOnInit() { }

getData(){
var url = "https://localhost:44354/api/employees_";
// alert("Get data");
this.data = this.http.get(url);
this.data.subscribe(data => {
this.result = data;
console.log(data);
})
}
postData(){
var url = "https://localhost:44354/api/employees_";
var durl="?Emp_Name=RinkeshGola&Address=Agra&Mobile=87878";
this.data = this.http.post(url+encodeURI(durl),"");
this.data.subscribe(data => {
console.log("show data : "+JSON.stringify(data));
})
}
}


No comments:

Post a Comment

Navigation in ionic or redirect in ionic

1.  Redirect as return View in mvc code in .ts       this .router.navigateByUrl( "/rec-view/" +d.Srno,{ skipLocationChange:tru e...