hannahhoward / a1atscript

The Angular 2 Polyfill
MIT License
101 stars 7 forks source link

add a `host` property to @Directive #21

Open timkindberg opened 9 years ago

timkindberg commented 9 years ago

See: http://victorsavkin.com/post/119943127151/angular-2-template-syntax. Scroll down to where he implements ng-model from scratch. Here's his code:

@Directive({
  selector: '[ng-model]',
  properties: ['ngModel'],
  events: ['ngModelChanged: ngModel'],
  host: {
    "[value]": 'ngModel',
    "(input)": "ngModelChanged.next($event.target.value)"
  }
})
class NgModelDirective {
  ngModel:any; // stored value
  ngModelChanged:EventEmitter; // an event emitter
}

See how it's possible to add host events, surrounded with '( )', and host property bindings, surrounded with '[ ]'. I feel like this should be possible. Behind the scenes we can get a reference to the element, perhaps from the link function and add the watches and/or event listeners and bind them to the controller class fields and methods.

Depends on #20