Blake
Blake

Reputation: 7547

How to get AngularJs route path right after domain part?

For example if I have this kind of url localhost/About, localhost/Projects, localhost/Photography, how can I get the value after localhost/, i.e About Projects Photography?

I have written my app.js as below:

angularSite.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/About', {
        templateUrl: 'partials/about.html',
       // controller: 'AboutController'
      }).
      when('/Projects', {
        templateUrl: 'partials/projects.html',
        controller: 'WorkController'
      }).
      when('/Photography', {
        templateUrl: 'partials/photo.html',

      }).
      otherwise({
        redirectTo: '/'
      });
  }]);

Upvotes: 0

Views: 457

Answers (1)

SomeKittens
SomeKittens

Reputation: 39522

If you need to get the current path in a controller/service/directive, $location.path() should do it (you'll need to inject $location).

Angular docs on $location

Upvotes: 1

Related Questions