Skip to content

Instantly share code, notes, and snippets.

@valorkin
Last active August 29, 2015 14:27
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 valorkin/ed9fdf26115400043eb8 to your computer and use it in GitHub Desktop.
Save valorkin/ed9fdf26115400043eb8 to your computer and use it in GitHub Desktop.
Is host element event handler is set?
// index.ts
// (close) could be set or not
@Component({
selector: 'app'
})
@View({
template: `
<alert (close)="closeAlert(i)">{{ alert1.msg }}</alert>
<alert>{{ alert2.msg }}</alert>
`,
directives: [AlertComponent, coreDirectives]
})
class Hello{}
// alerts.ts
@Component({
selector: 'alert',
properties: ['type'],
events: ['close'],
lifecycle: [LifecycleEvent.onInit]
})
@View({
template: `...doesn't care`,
directives: [coreDirectives, CSSClass]
})
class AlertComponent{
constructor(public el: ElementRef){
// TODO: is there a better way to detect that event handler is set?
this.closeable = el.nativeElement.getAttribute('(close)');
this.close = new EventEmitter();
}
}
@vsavkin
Copy link

vsavkin commented Aug 12, 2015

You can use <button [(ng-model)]="model.field">, you just need to defined a value accessor that will tell angular how to read and write a value to the button.

about first question I will have to use something like '[(close)]' to feat into ng2 mental model

[(a)] ="foo" just desugars to [a]="foo" (a)="foo=$event". I don't think it what you want. I was actually talking about the following: [show-close]="true" (close)="someHandler".

@valorkin
Copy link
Author

@vsavkin

you just need to defined a value accessor

yeap, debugged to this point yesterday,
now need to find about an interface of value accessor :)

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