Skip to content

vasudevan-palani/angular-promise-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-promise-router

This is an extension of the router provided by angular (ngRoute).

Its named as 'qRoute' named after $q of angularJS.

Reason for extending the ngRoute is to keep the route config manage the page flow. For page flows in controller today we use $location.url(). This is not a good design to have route URL's spread across the entire controller code base.

qRoute provides an alternative where the page flow is handled in the route configuration with the help of outcomes.

The below example should give a fair idea about how to use the module

Example

Step 1 : Include the qRoute module in your application

  angular.module('app', ['qRoute']).controller('myController', function($scope,$controller) {
  });

Step 2 : Create the route configuration

  angular.module('app').config(['$routeProvider',function($routeProvider){
      $routeProvider.when('/',{
        templateUrl : '/home.html',
        controller : 'HomeCtrl',
        // OUTCOMES mapped here
        //
        on : {
          'loginOK':'/dashboard'
        }
      })
      .when('/dashboard',{
        templateUrl : '/dashboard.html',
        controller : 'DashboardCtrl',
        on : {
          'logout':'/'
        }
      });
  }]);

Step3: Resolve the outcomes from controller

angular.module('app').controller('HomeCtrl', function($scope,$done,$timeout) {
  console.log("in Home Contoller");

  $scope.login = function(){
      $done('loginOK');
  }
});

angular.module('app').controller('DashboardCtrl', function($scope,$done,$timeout) {
  console.log("in Dashboard Contoller");

  $scope.logout = function(){
    $done('logout');
  }

});

About

Angular 1.x router based on promise

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published