Skip to content

add a host property to @Directive #21

Description

@timkindberg

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions