I would like to know how to pass parameter from url to php using http service.
service:
getEmployeesById(data) {
let datas = JSON.stringify({'id':data});
return this.http.get('http://localhost/employees/?p=editEmployees', datas)
.map(response => response.json() );
}
component:
ngOnInit() {
this.activatedRoute.queryParams.subscribe((queryParams: Params) => {
let userId = queryParams['id'];
this.employeesServices.getEmployeesById(userId)
.subscribe(data => {
this.result = data
});
});
}
PHP : http://localhost/employees/?p=editEmployees
$editEmployees = mysqli_query($con, "SELECT * FROM $employeesTable WHERE emp_id = '".$_GET['id']."' ");
$rows = mysqli_fetch_assoc($editEmployees);
$emp[] = $rows;
echo json_encode($emp);
-I created a mysqli query that gets the employee id. -Then in component, I fetched the emp id from url param(id) like this
this.employeesServices.getEmployeesById(userId);
My problem is, I dont know If I am passing the data correct.
I display the data in html using
{{ result.first_name }}
but I cant get it right.