I want to extract my url querystring using $location
like this example.
my url - .jsp?queryToken=123abc
and in my directive:
vm.queryParam = $location.search();
$log.log('vm.queryParam', vm.queryParam); //{}
vm.details.query = vm.queryParam.queryToken;
$log.log('vm.queryToken', vm.details.query); //undefined
I can see the param or params when logging $location
but what is the correct way to extract them when search()
does not work?
Thanks.
I want to extract my url querystring using $location
like this example.
my url - http://someDomain./create/index.jsp?queryToken=123abc
and in my directive:
vm.queryParam = $location.search();
$log.log('vm.queryParam', vm.queryParam); //{}
vm.details.query = vm.queryParam.queryToken;
$log.log('vm.queryToken', vm.details.query); //undefined
I can see the param or params when logging $location
but what is the correct way to extract them when search()
does not work?
Thanks.
Share Improve this question asked Jul 31, 2017 at 13:32 Itsik MauyhasItsik Mauyhas 4,00415 gold badges74 silver badges119 bronze badges 9- That is just returning the url I am on. – Itsik Mauyhas Commented Jul 31, 2017 at 13:36
- getting any error? – user8317956 Commented Jul 31, 2017 at 13:38
- No, I am a veteran in angular... – Itsik Mauyhas Commented Jul 31, 2017 at 13:39
- What are you getting from $location.search() ? – user8317956 Commented Jul 31, 2017 at 13:41
- @slacker an empty object. It's in the question. – George Commented Jul 31, 2017 at 13:42
2 Answers
Reset to default 5I have used this and it works, try using this
var app = angular.module('myApp', []);
app.config(['$locationProvider', function($locationProvider){
$locationProvider.html5Mode({
enabled: true,
requireBase: false
})
}])
app.controller('myCtrl', function($scope, $location) {
$scope.myPeram = "pass some value in url ?myParam=123";
var query = $location.search();
if(query.myParam)
$scope.myPeram = query.myParam;
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.3.20/angular.min.js"></script>
</script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<span ng-bind="myPeram"></span>
</div>
</body>
</html>
$location.search() will work only with HTML5 mode turned on.
Where you define your routes add this line:
$locationProvider.html5Mode(true);
This works always:
$window.location.search
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744385468a4571641.html
评论列表(0条)