Skip to content

Instantly share code, notes, and snippets.

@tothandras
Last active August 29, 2015 14:15
Show Gist options
  • Save tothandras/1b994a75f9d681a4dcb6 to your computer and use it in GitHub Desktop.
Save tothandras/1b994a75f9d681a4dcb6 to your computer and use it in GitHub Desktop.
Atom Snippets - Typescript AngularJS
###
# Angularjs + Typescript
###
'.source.ts':
'IFI':
'prefix': 'ifi'
'body': """
((): void => {
'use strict';
$1
})();
"""
'AngularJS Module':
'prefix': 'ngm'
'body': """
module $1 {
'use strict';
// register $1 module
angular.module('$1', [
]);
}
"""
'AngularJS Config':
'prefix': 'ngconf'
'body': """
module $1 {
'use strict';
/* @ngInject */
function config(): void {
}
angular.module('$1')
.config(config);
}
"""
'AngularJS State':
'prefix': 'ngstate'
'body': """
module $1 {
'use strict';
/* @ngInject */
function config($stateProvider: ng.ui.IStateProvider): void {
$stateProvider.state('$2', {
url: '/$2',
templateUrl: '$2.tpl.html',
controller: '$1.$3Controller',
controllerAs: '$2'
});
}
angular.module('$1')
.config(config);
}
"""
'AngularJS Controller':
'prefix': 'ngc'
'body': """
module $1 {
'use strict';
export interface I$2Scope {
}
class $2Controller implements I$2Scope {
name: string;
/* @ngInject */
constructor() {
this.name = '$2 Controller';
}
}
// register $2Controller
angular.module('$1')
.controller('$1.$2Controller', $2Controller);
}
"""
'AngularJS Directive':
'prefix': 'ngd'
'body': """
module $1 {
'use strict';
class $2Directive implements ng.IDirective {
restrict: string = 'E'; // element
scope: any = {
attr1: '=', // bidirection binding to an object
attr2: '&', // binding to an expression
attr3: '@' // binds to a string value
};
controller: string = '$2Controller';
controllerAs: string = '$3';
bindToController: boolean = true;
templateUrl: string = '$3.tpl.html';
transclude: boolean = false;
static instance(): $2Directive {
return new $2Directive;
}
// link(scope: ng.IScope,
// element: ng.IAugmentedJQuery,
// attrs: ng.IAttributes,
// controller: I$2Scope): void {
//
// }
}
// register $2 Directive
angular.module('$1')
.directive('$3', $2Directive.instance);
}
"""
'AngularJS Service':
'prefix': 'ngs'
'body': """
module $1 {
'use strict';
export interface I$2Service {
$3
}
class $2Service implements I$2Service {
$3
/* @ngInject */
constructor() {
}
}
// register $2Service
angular.module('$1')
.service('$1.$2Service', $2Service);
}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment