Last active
April 22, 2019 16:26
-
-
Save kudchikarsk/8bd47119bb360135bb5bd5c4f4e49993 to your computer and use it in GitHub Desktop.
Configure routes in Angularjs App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var app = angular.module('app', ['ngRoute']); | |
| app.config(['$logProvider', '$routeProvider', '$locationProvider', function ($logProvider, $routeProvider, $locationProvider) { | |
| $logProvider.debugEnabled(true); | |
| //$locationProvider.hashPrefix('!'); | |
| //$locationProvider.html5Mode(true); // use <base href="/"> in index.html | |
| $routeProvider | |
| .when('/', { | |
| controller: 'HomeController', | |
| controllerAs: 'home', | |
| templateUrl: '/app/templates/home.html' | |
| }) | |
| .when('/schools', { | |
| controller: 'AllSchoolsController', | |
| controllerAs: 'schools', | |
| templateUrl: '/app/templates/allSchools.html' | |
| }) | |
| .when('/classrooms', { | |
| controller: 'AllClassroomsController', | |
| controllerAs: 'classrooms', | |
| templateUrl: '/app/templates/allClassrooms.html' | |
| }) | |
| .when('/activities', { | |
| controller: 'AllActivitiesController', | |
| controllerAs: 'activities', | |
| templateUrl: '/app/templates/allActivities.html', | |
| resolve: { | |
| activities: function (dataService) { | |
| return dataService.getAllActivities(); | |
| } | |
| } | |
| }) | |
| .when('/classrooms/:id', { | |
| templateUrl: '/app/templates/classroom.html', | |
| controller: 'ClassroomController', | |
| controllerAs: 'classroom' | |
| }) | |
| .when('/classrooms/:id/detail/:month?', { | |
| templateUrl: '/app/templates/classroomDetail.html', | |
| controller: 'ClassroomController', | |
| controllerAs: 'classroom' | |
| }) | |
| .otherwise('/'); | |
| }]); | |
| app.run(['$rootScope', '$log', function($rootScope, $log) { | |
| $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { | |
| $log.debug('successfully changed routes'); | |
| $log.debug(event); | |
| $log.debug(current); | |
| $log.debug(previous); | |
| }); | |
| $rootScope.$on('$routeChangeError', function (event, current, previous, rejection) { | |
| $log.debug('error changing routes'); | |
| $log.debug(event); | |
| $log.debug(current); | |
| $log.debug(previous); | |
| $log.debug(rejection); | |
| }); | |
| }]); | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment