Skip to content

Instantly share code, notes, and snippets.

@alexanderjeurissen
Created September 28, 2014 13:45
Show Gist options
  • Save alexanderjeurissen/0de64c1b2e561c3077a3 to your computer and use it in GitHub Desktop.
Save alexanderjeurissen/0de64c1b2e561c3077a3 to your computer and use it in GitHub Desktop.
## Global Snippets
# Define a new Angular Controller;
# You can change the controller name and parameters
snippet ngc
.controller(${1:controllerName}, ['$scope', '${2:controllerDependencies}',
function($scope, ${4:injectables}) {
${5}
};
]);
# angular.foreach loop
snippet ngfor
angular.forEach(${1:iterateOver}, function(value, key) {
${2}
});
## Module Based Snippets
# A new angular module without a config function
snippet ngm
angular.module('${1:moduleName}', ['${2:moduleDependencies}']);
${3}
# A new angular module without a config function and a variable assignment
snippet ngma
var ${1:moduleName} = angular.module('$1', ['${2:moduleDeps}']);
${3}
# A new angular module with a config function
snippet ngmc
var ${1:moduleName} = angular.module('$1', ['${2:moduleDeps}'], function(${3:configDeps}) {
${4}
});
# reopen an already existing angular module
snippet ngmo
'use strict'
angular.module('${1:appName}')
${2}
# A factory in a module
snippet ngmfa
.factory('${1:factoryName}', ['${2:factoryDependencies}',
function(${3:injectables}) {
${3}
}
]);
# Define an Angular Module Service to be attached to a previously defined module
# You can change the service name and service injectables
snippet ngms
.service('${1:serviceName}', ['${2:serviceDependencies}',
function(${3:injectables}) {
${4}
}
]);
# Define an Angular Module Filter to be attached to a previously defined module
# You can change the filter name
snippet ngmfi
.filter('${1:filterName}', ['${2:filterDependencies}',
function(${3:injectables}) {
return function(input, ${4:args}) {
${5}
};
}
]);
## Route Based Snippets
# Defines a when condition of an AngularJS route
snippet ngrw
$routeProvider.when('${1:url}', {
templateUrl: '${2:templateUrl}',
controller: '${3:controller}'
});
${4}
# Defines a when condition of an AngularJS route with the resolve block
snippet ngrwr
$routeProvider.when('${1:url}', {
templateUrl: '${2:templateUrl}',
controller: '${3:controller}',
resolve: {
${4}
}
});
${5}
# Defines an otherwise condition of an AngularJS route
snippet ngro
$routeProvider.otherwise({
redirectTo: '${1:url}'
});
${2}
## Scope Related Snippets
# Define a new $scope'd function (usually inside an AngularJS Controller)
# You can change the function name and arguments
snippet $f
$scope.${1:functionName} = function(${2:args}) {
${3}
};
# Defines a new $scope'd variable inside an AngularJS controller
snippet $v
$scope.${1:variable} = ${2:value};
${3}
# Defines a new $scope'd variable inside an AngularJS controller and assigns a value from a constructor arguments
snippet $va
$scope.${1:variable} = ${2:variable};
${3}
# Define a $watch for an expression
# You can change the expression to be watched
snippet $w
$scope.$watch('${1:watchExpr}', function(newValue, oldValue) {
${2}
});
# Define a $on for a $broadcast/$emit on the $scope inside an Angular Controller
# You can change the event name to listen on
snippet $on
$scope.$on('${1:eventName}', function(event, ${2:args}) {
${3}
});
# Define a $broadcast for a $scope inside an Angular Controller / Angular Controller Function
# You can change the event name and optional event arguments
snippet $b
$scope.$broadcast('${1:eventName}', ${2:eventArgs});
${3}
# Define an $emit for a $scope inside an Angular Controller / Angular Controller Function
# You can change the event name and optional event arguments
snippet $e
$scope.$emit('${1:eventName}', ${2:eventArgs});
${3}
## Directive related snippets
# A compile function
snippet ngdcf
compile: function(tElement, tAttrs, transclude) {
return function(scope, element, attrs) {
${1}
}
}
# A linking function in a directive
snippet ngdlf
link: function(scope, element, attrs, ${1:ctrl}) {
${2}
}
# A directive with a compile function
snippet ngdc
.directive('${2:directiveName}', ['${3:injectService}',
function(${4:injectService}) {
return {
restrict: '${5:restrictType}',
scope: {
${6://scopeVariables}
},
controller: ${7://controller},
transclude: ${8://transclude?},
templateUrl: '${9://templateUrl}',
compile: function compile(tElement, tAttrs, transclude) {
return function (scope, element, attrs) {
${10://compile content here}
}
}
};
}
]);
# A directive with a linking function only
snippet ngdl
.directive('${2:directiveName}', ['${3:injectService}',
function(${4:injectService}) {
return {
restrict: '${5:restrictType}',
scope: {
${6://scopeVariables}
},
controller: ${7://controller},
transclude: ${8://transclude?},
templateUrl: '${9://templateUrl}',
link: function(scope, element, attrs) {
${10://link content here}
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment