Thursday, May 15, 2014

Angular.js: optional route parameters

The route module in Angular.js supports optional parameters. You can specify that a parameter is optional by adding a ‘?’ after the route parameter:

maintenanceApp.config(['$routeProvider', function ($routeProvider) {

$routeProvider

    .when('/', { templateUrl: '/Apps/MaintenanceApp/partials/applications.html' })

            .when('/applications/', { templateUrl: '/Apps/MaintenanceApp/partials/applications.html' })

            .when('/environments/', { templateUrl: '/Apps/MaintenanceApp/partials/environments.html' })

            .when('/editApplication/:id?', { templateUrl: '/Apps/MaintenanceApp/partials/editApplication.html' })

            .when('/editEnvironment/:id?', { templateUrl: '/Apps/MaintenanceApp/partials/editEnvironment.html' })

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

    }]);

No comments: