Skip to content

Commit 1f54e64

Browse files
committed
feat(PropertyBindingParser): support onbubble-event as an alternate syntax for (^event)
fixes angular#3448 Closes angular#3616
1 parent 20cf617 commit 1f54e64

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

modules/angular2/src/render/dom/compiler/property_binding_parser.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import {dashCaseToCamelCase} from '../util';
1212
// Group 1 = "bind-"
1313
// Group 2 = "var-" or "#"
1414
// Group 3 = "on-"
15-
// Group 4 = "bindon-"
16-
// Group 5 = the identifier after "bind-", "var-/#", or "on-"
17-
// Group 6 = idenitifer inside [()]
18-
// Group 7 = idenitifer inside []
19-
// Group 8 = identifier inside ()
15+
// Group 4 = "onbubble-"
16+
// Group 5 = "bindon-"
17+
// Group 6 = the identifier after "bind-", "var-/#", or "on-"
18+
// Group 7 = idenitifer inside [()]
19+
// Group 8 = idenitifer inside []
20+
// Group 9 = identifier inside ()
2021
var BIND_NAME_REGEXP =
21-
/^(?:(?:(?:(bind-)|(var-|#)|(on-)|(bindon-))(.+))|\[\(([^\)]+)\)\]|\[([^\]]+)\]|\(([^\)]+)\))$/g;
22+
/^(?:(?:(?:(bind-)|(var-|#)|(on-)|(onbubble-)|(bindon-))(.+))|\[\(([^\)]+)\)\]|\[([^\]]+)\]|\(([^\)]+)\))$/g;
2223
/**
2324
* Parses the property bindings on a single element.
2425
*/
@@ -38,30 +39,33 @@ export class PropertyBindingParser implements CompileStep {
3839
var bindParts = RegExpWrapper.firstMatch(BIND_NAME_REGEXP, attrName);
3940
if (isPresent(bindParts)) {
4041
if (isPresent(bindParts[1])) { // match: bind-prop
41-
this._bindProperty(bindParts[5], attrValue, current, newAttrs);
42+
this._bindProperty(bindParts[6], attrValue, current, newAttrs);
4243

4344
} else if (isPresent(
4445
bindParts[2])) { // match: var-name / var-name="iden" / #name / #name="iden"
45-
var identifier = bindParts[5];
46+
var identifier = bindParts[6];
4647
var value = attrValue == '' ? '\$implicit' : attrValue;
4748
this._bindVariable(identifier, value, current, newAttrs);
4849

4950
} else if (isPresent(bindParts[3])) { // match: on-event
50-
this._bindEvent(bindParts[5], attrValue, current, newAttrs);
51+
this._bindEvent(bindParts[6], attrValue, current, newAttrs);
5152

52-
} else if (isPresent(bindParts[4])) { // match: bindon-prop
53-
this._bindProperty(bindParts[5], attrValue, current, newAttrs);
54-
this._bindAssignmentEvent(bindParts[5], attrValue, current, newAttrs);
53+
} else if (isPresent(bindParts[4])) { // match: onbubble-event
54+
this._bindEvent('^' + bindParts[6], attrValue, current, newAttrs);
5555

56-
} else if (isPresent(bindParts[6])) { // match: [(expr)]
56+
} else if (isPresent(bindParts[5])) { // match: bindon-prop
5757
this._bindProperty(bindParts[6], attrValue, current, newAttrs);
5858
this._bindAssignmentEvent(bindParts[6], attrValue, current, newAttrs);
5959

60-
} else if (isPresent(bindParts[7])) { // match: [expr]
60+
} else if (isPresent(bindParts[7])) { // match: [(expr)]
6161
this._bindProperty(bindParts[7], attrValue, current, newAttrs);
62+
this._bindAssignmentEvent(bindParts[7], attrValue, current, newAttrs);
63+
64+
} else if (isPresent(bindParts[8])) { // match: [expr]
65+
this._bindProperty(bindParts[8], attrValue, current, newAttrs);
6266

63-
} else if (isPresent(bindParts[8])) { // match: (event)
64-
this._bindEvent(bindParts[8], attrValue, current, newAttrs);
67+
} else if (isPresent(bindParts[9])) { // match: (event)
68+
this._bindEvent(bindParts[9], attrValue, current, newAttrs);
6569
}
6670
} else {
6771
var expr = this._parser.parseInterpolation(attrValue, current.elementDescription);

modules/angular2/test/render/dom/compiler/property_binding_parser_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ export function main() {
171171
expect(eventBinding.fullName).toEqual('click');
172172
});
173173

174+
it('should detect onbubble- syntax', () => {
175+
var results = process(el('<div onbubble-click="b()"></div>'));
176+
var eventBinding = results[0].eventBindings[0];
177+
expect(eventBinding.source.source).toEqual('b()');
178+
expect(eventBinding.fullName).toEqual('^click');
179+
});
180+
181+
it('should detect onbubble- syntax with data- prefix', () => {
182+
var results = process(el('<div data-onbubble-click="b()"></div>'));
183+
var eventBinding = results[0].eventBindings[0];
184+
expect(eventBinding.source.source).toEqual('b()');
185+
expect(eventBinding.fullName).toEqual('^click');
186+
});
187+
174188
it('should parse event handlers using on- syntax as actions', () => {
175189
var results = process(el('<div on-click="foo=bar"></div>'));
176190
var eventBinding = results[0].eventBindings[0];

0 commit comments

Comments
 (0)