0

I need to read URL parameters from browser and assign it to a variable. My url will be like http://localhost:9090/ngdemo/apd.html?id=bookid-1 . I need to get bookid-1 from the url. I tried $location.search(), $location.$$path but I am not getting the value 'bookid-1' .

My controller code is

app.controller('apdController', function($scope, getTocService,$location,$routeParams) {
    var bookId = $location.search();
    var param1 = $routeParams.param1;

});

app.js

app.config(['$routeProvider', function ($routeProvider) {

    $routeProvider.when('/view3/:param1', {templateUrl: 'apd.html', controller: 'apdController'});
    $routeProvider.otherwise({redirectTo: '/view1'});
}]);

What is the change I need to make to get bookid-1 here?

4
  • 1
    Did you try $location.search().id? Commented Jan 5, 2016 at 4:36
  • your parameter is id, not bookId nor param1. have you tried var bookId = $routeParams.id;? Commented Jan 5, 2016 at 4:38
  • do you have ui-router or ng-router? Commented Jan 5, 2016 at 4:39
  • @Phil. Thanks a lot..! Worked perfectly with $location.search().id..Please put it as answer. I will accept it. Commented Jan 5, 2016 at 4:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.