I'm defining my routes like this.
$routeProvider
.when('/Home', {
name: 'Main',
templateUrl: 'Main.html',
controller: 'MainController',
controllerAs: 'ctrl'
})
.when('/About', {
name: 'About',
templateUrl: 'About.html',
controller: 'AboutController',
controllerAs: 'ctrl'
})
How can I in a controller find the '/About' URL by querying on the name 'About', when I'm in the Main controller?
You can inject $location
to your controller and get the URL using $location.path()
or inject $route
to get the route name.
Example:
function MainCntl($scope,$location,$route) {
$scope.location = $location.path(); // '/Home'
$scope.routeName= $route.current.$$route.name; //'Main'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With