feat(Directives): add the ability to declaratively bind events
relates to #621
This commit is contained in:
@ -183,7 +183,7 @@ function getElementDescription(domElement):string {
|
||||
|
||||
buf.add("<");
|
||||
buf.add(DOM.tagName(domElement).toLowerCase());
|
||||
|
||||
|
||||
// show id and class first to ease element identification
|
||||
addDescriptionAttribute(buf, "id", MapWrapper.get(atts, "id"));
|
||||
addDescriptionAttribute(buf, "class", MapWrapper.get(atts, "class"));
|
||||
|
@ -152,7 +152,9 @@ export class ElementBinderBuilder extends CompileStep {
|
||||
if (isPresent(current.eventBindings)) {
|
||||
this._bindEvents(protoView, current);
|
||||
}
|
||||
this._bindDirectiveProperties(current.getAllDirectives(), current);
|
||||
var directives = current.getAllDirectives();
|
||||
this._bindDirectiveProperties(directives, current);
|
||||
this._bindDirectiveEvents(directives, current);
|
||||
} else if (isPresent(parent)) {
|
||||
elementBinder = parent.inheritedElementBinder;
|
||||
}
|
||||
@ -199,6 +201,19 @@ export class ElementBinderBuilder extends CompileStep {
|
||||
});
|
||||
}
|
||||
|
||||
_bindDirectiveEvents(directives: List<DirectiveMetadata>, compileElement: CompileElement) {
|
||||
for (var directiveIndex = 0; directiveIndex < directives.length; directiveIndex++) {
|
||||
var directive = directives[directiveIndex];
|
||||
var annotation = directive.annotation;
|
||||
if (isBlank(annotation.events)) continue;
|
||||
var protoView = compileElement.inheritedProtoView;
|
||||
StringMapWrapper.forEach(annotation.events, (action, eventName) => {
|
||||
var expression = this._parser.parseAction(action, compileElement.elementDescription);
|
||||
protoView.bindEvent(eventName, expression, directiveIndex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_bindDirectiveProperties(directives: List<DirectiveMetadata>,
|
||||
compileElement: CompileElement) {
|
||||
var protoView = compileElement.inheritedProtoView;
|
||||
|
Reference in New Issue
Block a user