Skip to content

Instantly share code, notes, and snippets.

@katrotz
Last active October 16, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katrotz/1db70bea9670db428c82234cf469e779 to your computer and use it in GitHub Desktop.
Save katrotz/1db70bea9670db428c82234cf469e779 to your computer and use it in GitHub Desktop.
Collection of angular 2 annotations (typescript decorators) written in EcmaScript

TYPESCRIPT

@Component({
  selector: 'cmp',
  template: `
    <h1>"Anything less than immortality is a complete waste of time" (c)Bender</h1>
    <p>Cmp input: {{cmpInput}}</p>
    <p>Aliased input: {{aliasedInputName}}</p>
  `
})
class CmpComponent {
  @Input() cmpInput: string;
  @Input('bindedInputName') aliasedInputName: string;
  @Output() cmpOutput = new EventEmitter<string>();
  constructor(router: Router, @Optional() public cmpComponentDependency: CmpComponentDependency) {}
}

ECMASCRIPT

class CmpComponent {
  static get annotations() {
    return [
      new Component({
        selector: 'cmp',
        template: `
          <h1>"Anything less than immortality is a complete waste of time" (c)Bender</h1>
          <p>Cmp input: {{cmpInput}}</p>
          <p>Aliased input: {{aliasedInputName}}</p>
        `,
        inputs: ['cmpInput:cmpInput', 'bindedInputName:aliasedInputName'],
        outputs: ['cmpOutput']
      })
    ]
  }
  
  static get parameters() {
    return [
      [Router],
      [new Optional(), CmpComponentDependency]
    ]
  }
  
  constructor(router, cmpComponentDependency) {
    this.router = router;
    this.cmpComponentDependency = cmpComponentDependency;
    this.cmpOutput = new EventEmitter();
  }
  
  ngOnInit() {
    this.cmpOutput.emit('Emitted value');
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment