Provider | Singleton | Instantiable | Configurable |
---|---|---|---|
Constant | Yes | No | No |
Value | Yes | No | No |
Service | Yes | No | No |
Factory | Yes | Yes | No |
Decorator | Yes | No? | No |
Provider | Yes | Yes | Yes |
app.directive("ngTap", ["$parse", function($parse) { | |
return function($scope, $element, $attributes) { | |
var tapped; | |
tapped = false; | |
$element.bind("click", function(event) { | |
if (!tapped) { | |
var fn = $parse($attributes["ngTap"]); | |
$scope.$apply(function() { | |
fn($scope, {$event:event}); | |
}); |
var interceptor = angular.module('Interceptor',[]); | |
interceptor.factory('HttpInterceptor', function ($q, $rootScope, $log) { | |
var numLoadings = 0; | |
return { | |
request: function (config) { | |
numLoadings++; |
var spawn = require('child_process').spawn; | |
function spawnProcess(dir, cmd) { | |
return (process.platform.toLowerCase().indexOf("win") >= 0) | |
? spawnWindowsProcess(dir, cmd) | |
: spawnLinuxProcess(dir, cmd); | |
} | |
function spawnWindowsProcess(dir, cmd) { | |
return spawn("cmd.exe", ["/c", cmd], {cwd: dir}); |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
var scrollCap = function ($element) { | |
$element.on('touchstart.scroll-cap', function(event){ | |
var $element = $(this); | |
var scrollTop = $element.scrollTop(); | |
var contentHeight = $element.get(0).scrollHeight; | |
var minScrollTop = 1; | |
var maxScrollTop = contentHeight - $element.height() - 1; | |
if(scrollTop < minScrollTop){ | |
$element.scrollTop(minScrollTop); |
This gist is in response to a question asked on the Reddit Angular JS forum about how to structure an Angular app with roles and permissions.
There are many ways to approach this, but I'll share one that I've used before and maybe it will give you an idea. I'd combine all of the above into a single app and control who gets to see what using permissions. There are a few components to this approach...
First off I'd advise creating some sort of local session management service. This should be able to track whether you have an authenticated user and- if so- what types of permissions that user has. (Lots of ways to manage permissions. I'll assume your user object has either a 'role' enum or something simple like an array of string permissions.) You could roll your own session service or you could check out something like satellizer.
Let's assume yo
Single Page Apps are ruling the world and AngularJS is leading the charge. But many of the lessons we learned in the Web 2.0 era no longer apply, and few are as drastically different as authentication.
CORS is an oft-misunderstood feature of new browsers that is configured by a remote server. CORS stands for Cross-Origin-Resource-Sharing, and was designed to make it possible to access services outside of the current origin (or domain) of the current page.
Like many browser features, CORS works because we all agree that it works. So all major browsers like Chrome, Firefox, and IE support and enforce it. By using these browsers, you benefit from the security of CORS.
That means certain browsers do not enforce it, so it is not relevant there. One large example is a native Web View for things like Cordova and Phonegap. However, these tools often have configuration options for whitelisting domains so you can add some security that way.
(function () { | |
'use strict'; | |
// Define the factory on the module. | |
// Inject the dependencies. | |
// Point to the factory definition function. | |
angular.module('brew-everywhere').factory('messaging_service', | |
[messaging_service]); | |
function messaging_service() { |
(function () { | |
/* | |
* @name ngRightClick | |
* @type Directive | |
* @desc Binds the right click to a javascript function by using the ng-right-click attribute | |
*/ | |
function ngRightClick($parse) { | |
return function (scope, element, attrs) { |