Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $routeProvider
- .when('/Home', {
- name: 'Main',
- templateUrl: 'Main.html',
- controller: 'MainController',
- controllerAs: 'ctrl'
- })
- .when('/About', {
- name: 'About',
- templateUrl: 'About.html',
- controller: 'AboutController',
- controllerAs: 'ctrl'
- })
- $provide.decorator('$route', ($delegate) => {
- $delegate.getRoute = (name) => {
- var result = null;
- angular.forEach($delegate.routes, (config, route) => {
- if (config.name === name) {
- result = route;
- }
- });
- return result;
- };
- return $delegate;
- });
- function MainCntl($scope,$location,$route) {
- $scope.location = $location.path(); // '/Home'
- $scope.routeName= $route.current.$$route.name; //'Main'
- }
- Object.getPrototypeOf($route.current) === $route.routes['/Home'];
- $rootScope.$on('$routeChangeSuccess', function(e, curr, prev) {
- if (Object.getPrototypeOf($route.current) === $route.routes['/Home']) {
- // do something when route changes to /Home
- }
- else if (Object.getPrototypeOf($route.current) === $route.routes['/About']) {
- // do something when route changes to /About
- }
- }
- function MainCntl($scope, $location) {
- // put this at where your want to find the '/About' URL
- $location.path('/About');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement