1

I am having the url as follows:

http://test.com/#/mya/classified/42/

How can I fetch 42 from this usl in angularjs? Is there any way in angularjs $location to fetch the same?.

6
  • Are you using states for URL routing? Anyway, show how do you manage URL routing in your app. Thanks. Commented Sep 29, 2014 at 19:18
  • Yes, I am using ui-router. Commented Sep 29, 2014 at 19:22
  • .state('mya.viewOrder', { abstract: true, url: 'orders/:id/', templateUrl: './partials/mya/order/view.html', controller: 'MyaOrderViewCtrl' }) Commented Sep 29, 2014 at 19:23
  • try this, i guess it should give your params in url var location = $location.search(); ...and if you have many params in your url ..you can choose particular param using $location.search().paramName; Commented Sep 29, 2014 at 19:24
  • It gives param values only. search function process the values after ?. Commented Sep 29, 2014 at 19:27

1 Answer 1

4

This is what $stateParams service is for:

myApp.controller('MyCtrl', ['$scope', '$stateParams',
    function ($scope, $stateParams) {
        console.log($stateParams.id);
}]);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.