Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. $routeProvider
  2. .when('/Home', {
  3. name: 'Main',
  4. templateUrl: 'Main.html',
  5. controller: 'MainController',
  6. controllerAs: 'ctrl'
  7. })
  8. .when('/About', {
  9. name: 'About',
  10. templateUrl: 'About.html',
  11. controller: 'AboutController',
  12. controllerAs: 'ctrl'
  13. })
  14.  
  15. $provide.decorator('$route', ($delegate) => {
  16.  
  17. $delegate.getRoute = (name) => {
  18. var result = null;
  19. angular.forEach($delegate.routes, (config, route) => {
  20. if (config.name === name) {
  21. result = route;
  22. }
  23. });
  24. return result;
  25. };
  26.  
  27. return $delegate;
  28. });
  29.  
  30. function MainCntl($scope,$location,$route) {
  31. $scope.location = $location.path(); // '/Home'
  32. $scope.routeName= $route.current.$$route.name; //'Main'
  33. }
  34.  
  35. Object.getPrototypeOf($route.current) === $route.routes['/Home'];
  36.  
  37. $rootScope.$on('$routeChangeSuccess', function(e, curr, prev) {
  38. if (Object.getPrototypeOf($route.current) === $route.routes['/Home']) {
  39. // do something when route changes to /Home
  40. }
  41.  
  42. else if (Object.getPrototypeOf($route.current) === $route.routes['/About']) {
  43. // do something when route changes to /About
  44. }
  45. }
  46.  
  47. function MainCntl($scope, $location) {
  48.  
  49. // put this at where your want to find the '/About' URL
  50. $location.path('/About');
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement