New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ng-conditions

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-conditions

Create conditions that can return promises and provide an onError callback

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Condition Factory Angular Component

Build Status

Usage

var condition = ConditionFactory.createCondition(
	check, // check function must return either Boolean or Boolean promise
	onError // callback function
);

Returns a condition object

{
  check: check,
  resolve: function(){...} // returns promise that rejects if condition check fails,
  onError: onError
}

Rejection object:

{
  type: ConditionFactory.CONDITION_TYPE,
  onError: onError
}

Examples

RoutingConditions.userIsLoggedIn = ConditionFactory.createCondition(
	function() {
		return !!UserService.getToken();
	},
	function() {
	  redirectTo('login')
	}
);
RoutingConditions.userIsNotLoggedIn = ConditionFactory.createReversedCondition(
	RoutingConditions.userIsLoggedIn,
	function() {
	  redirectTo('profile')
	}
);

// Routing
$routeProvider
	.when('/profile', {
		templateUrl: '/templates/profile.html',
		controller: 'ProfileController',
		controllerAs: 'vm',
		resolve: {
			canAccess: function(RoutingConditions) {
				return RoutingConditions.userIsLoggedIn.resolve();
			}
		}
	})
	.when('/login', {
		templateUrl: '/templates/login.html',
		controller: 'LoginController',
		controllerAs: 'vm',
		resolve: {
			canAccess: function(RoutingConditions) {
				return RoutingConditions.userIsNotLoggedIn.resolve();
			}
		}
	})
	.when('/error', {
		templateUrl: '/templates/error.html',
		controller: 'ErrorController',
		controllerAs: 'vm',
	});

// Handle the unresolved conditions used in routes
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
	console.log("route rejection: cannot go to " + current.$$route.originalPath);
	console.log(rejection);
	try {
		rejection.onError();
	} catch(event) {
		redirectTo('error');
	}
});

Keywords

FAQs

Package last updated on 08 Jul 2016

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc