Last active
August 29, 2015 14:27
-
-
Save valorkin/ed9fdf26115400043eb8 to your computer and use it in GitHub Desktop.
Is host element event handler is set?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} |
about first question I will have to use something like '[(close)]' to feat into ng2 mental model
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"
.
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
@vsavkin ok another quesion :)
if I want to implement http://angular-ui.github.io/bootstrap/#/buttons in
angular2 I can not use somewhat near ng-model, and have to update model like this
or there are a way to implement
?
Thank in advance :)