Using $location.search() you can easily get the query parameter.
I have written the same using Angular 2(+) concept as well, check these links for that Get Url parameter using Angular 4 and 3 simple ways to share data through angular route.
For example
//url
http://www.sample.com/#/?username='samplename'&tocken='tocken'
//Note '#/'
//In your controller
$location.search();
Result:
{
username : 'samplename',
tocken:'tocken'
}
Even you can try ,
$location.search().username
$location.search().tocken
//you can write your own logic
if($location.search().username && $location.search().tocken){
//do your logic
}
Check query parameter is existing
if($location.search().yourQueryData.indexOf('?') > 0)
{
//query parameter existing
}
else{
//no
}
Related Posts
1. Angular js client side pagination like google.
2. Angular Loader using font awesome icons
3. Angular js add class to active element
not working. I get undefined from property($location.search().tab) that i needed and my url ends with "?tab=2"
ReplyDeleteIt should work ,did you added dependencies properly ($location)
Deletehtml5Mode must be enabled for this to work.
ReplyDeleteangular.module('myApp', [], function($locationProvider) {
$locationProvider.html5Mode(true);
});
the first your url demo is error, need use /# intead for #/
ReplyDeletethat was a typo,corrected ,thanks
Deletewhen i add the code..pages not working
Delete$locationProvider.html5Mode(true);
what error you are getting.
DeleteThanks! That worked for me
ReplyDeleteworked for me thanks
ReplyDeletewindow.location = "/UIPortal/Transactions/RatingInfo.html?series=" + Series;
ReplyDeletethe above is my url, i am getting undefined in the below line
$location.search().series
I applied below in module
var TM = angular.module('app', ['datatables', 'datatables.buttons', 'datatables.columnfilter', 'datePicker'], function ($locationProvider) {
$locationProvider.html5Mode(true);
});
Only works with base-tag, correct?
ReplyDeleteGood article that provides a good example of the great use of Angular JS in HTML. Thanks for providing us this very unique example in your blog.
ReplyDelete