Socket
Book a DemoInstallSign in
Socket

angular-promise-router

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-promise-router

Promise based router for angularjs

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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');
  }

});

Keywords

Promise

FAQs

Package last updated on 06 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.