I have a URL like this http://localhost/phpdemo/edit_data.php?edt_id=1
. Here I need the query string value which is 1
. By using Angular.js, I am getting the following output in browser's console.
id is : Object {}
My code is given below.
update.js:
var app=angular.module("edit_data", []);
app.controller("updateController",function($scope,$http,$location){
$scope.errors = [];
$scope.msgs = [];
var id=$location.search();
console.log("id is :",id);
$http.get('js/edit.php',{"user_id":$location.hash()}).success(function(response){
console.log('response',response);
});
$scope.update_data=function(){
$http.post('js/update.php',{"first_name":$scope.first_name,"last_name":$scope.last_name,"city":$scope.city}
).success(function(data, status, headers, config){
if(data.msg!=''){
$scope.msgs.push(data.msg);
}else{
$scope.errors.push(data.error);
}
}).error(function(data, status) { // called asynchronously if an error occurs
// or server returns response with an error status.
$scope.errors.push(status);
});
}
});
Please help me to resolve this issue.
This $location.search();
return an array, so
console.log("id is :",id[0]);
Can you try with above.
UPDATE:
$location.search()['edt_id']
It must return the value 1
$location.search() will return an object of key-value pairs, the same pairs as the query string. A key that has no value is just stored in the object as true. In this case, the object would be:
var id=$location.search().edt_id;
Location service Search Little Brief
search(search, [paramValue]); This method is getter / setter.
Return search part (as object) of current url when called without any parameter.
Change search part when called with parameter and return $location.
// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var searchObject = $location.search();
// => {foo: 'bar', baz: 'xoxo'}
// set foo to 'yipee'
$location.search('foo', 'yipee');
// $location.search() => {foo: 'yipee', baz: 'xoxo'}