I have java script function which gives current lat long inside that function making an http post call like this \"this.http.post\" but the value of this null inside the
Try like this :
use .bind(this)
end of the function
ngOnInit(): void {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(p) {
var LatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
console.log(p.coords.latitude);
console.log(p.coords.longitude);
var dataObj = {
latitude: p.coords.latitude,
longitude: p.coords.longitude
};
this.http.post('https://XXXXX/datacenteres.php', {
dataObj
}).subscribe(res => {
console.log(res);
}, err => {
console.log("Error occured");
});
}.bind(this));
}
}