Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit a37e157

Browse files
mralephmhevery
authored andcommitted
fix(NgAttrMustacheDirective): support parsing of multiline attribute values
1 parent ad7a397 commit a37e157

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

lib/core_dom/ng_mustache.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ class NgTextMustacheDirective {
2121

2222
@NgDirective(selector: r'[*=/{{.*}}/]')
2323
class NgAttrMustacheDirective {
24-
static RegExp ATTR_NAME_VALUE_REGEXP = new RegExp(r'^([^=]+)=(.*)$');
25-
26-
// This Directive is special and does not go through injection.
24+
// This Directive is special and does not go through injection.
2725
NgAttrMustacheDirective(NodeAttrs attrs, String markup, Interpolate interpolate, Scope scope) {
28-
var match = ATTR_NAME_VALUE_REGEXP.firstMatch(markup);
29-
var attrName = match[1];
30-
Interpolation interpolation = interpolate(match[2]);
26+
var eqPos = markup.indexOf('=');
27+
var attrName = markup.substring(0, eqPos);
28+
var attrValue = markup.substring(eqPos + 1);
29+
Interpolation interpolation = interpolate(attrValue);
3130
interpolation.setter = (text) => attrs[attrName] = text;
3231
interpolation.setter('');
3332
scope.$watchSet(interpolation.watchExpressions, interpolation.call, markup.trim());

test/core_dom/ng_mustache_spec.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ main() {
5050
expect(element.attr('some-attr')).toEqual('OK');
5151
expect(element.attr('other-attr')).toEqual('23');
5252
}));
53+
54+
55+
it('should allow newlines in attribute', inject((Compiler $compile, Scope $rootScope, Injector injector) {
56+
var element = $('<div multiline-attr="line1: {{line1}}\nline2: {{line2}}"></div>');
57+
var template = $compile(element);
58+
59+
$rootScope.line1 = 'L1';
60+
$rootScope.line2 = 'L2';
61+
var block = template(injector);
62+
63+
element = $(block.elements);
64+
65+
expect(element.attr('multiline-attr')).toEqual('');
66+
$rootScope.$digest();
67+
expect(element.attr('multiline-attr')).toEqual('line1: L1\nline2: L2');
68+
}));
5369
});
5470

5571
describe('NgShow', () {

0 commit comments

Comments
 (0)