Skip to content

Instantly share code, notes, and snippets.

@jimthedev
Created September 23, 2015 05:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jimthedev/29ac38a7734d64838e79 to your computer and use it in GitHub Desktop.
Save jimthedev/29ac38a7734d64838e79 to your computer and use it in GitHub Desktop.
A few Visual Studio Code 0.8 Snippets for TypeScript and Angular 2
{
"New NG2 Component (Item)": {
"prefix": "ng2c",
"body": [
"import {Component, View, CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/angular2';",
"// import {ExampleListComponent} from '../example/example-list.component';",
"",
"@Component({",
" selector: '${1:dashed-name}',",
" properties: ['id']",
"})",
"@View({",
" directives: [ CORE_DIRECTIVES, FORM_DIRECTIVES/*, ExampleListComponent*/],",
" styles: [`",
" ${1:dashed-name}-contents { }",
" `],",
" template: `",
" <${1:dashed-name}-contents>",
" <id>${1:dashed-name} {{id}}</id>:",
" <!-- <example-list></example-list> -->",
" </${1:dashed-name}-contents>",
" `",
"})",
"export class ${2:CapitalCaseName}Component {",
" constructor(${3:public serviceInjections:ServiceInjections}) {",
" ${4://Press ESC to finish or Tab to start over}",
" }",
" onInit() {",
" }",
"}"
],
"description": "Create a new Angular2 single item component in this file."
},
"New NG2 Directive": {
"prefix": "ng2d",
"body": [
"import {Directive, ElementRef} from 'angular2/angular2';",
"",
"@Directive({",
" selector: '[${1:selector}]' // using [ ] means selecting attributes",
"})",
"export class ${2:}Directive {",
" constructor(element: ElementRef) {",
" // simple DOM manipulation to set font size to x-large",
" // `nativeElement` is the direct reference to the DOM element",
" element.nativeElement.fontSize = 'x-large';$3",
" }",
"}"
],
"description": "Create a new Angular2 directive in this file."
},
"New Import": {
"prefix": "imp",
"body": [
"import {${1}} from '${2:moduleOrPath}';",
"${3}"
],
"description": "Import a module."
},
"Import Standard Component": {
"prefix": "impc",
"body": [
"import {${1:CapitalCase}Component} from '../${2:dash-case}/${2:dash-case}.component';",
"${3}"
],
"description": "Import a module."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment