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

Commit d658909

Browse files
vsavkinrkirov
authored andcommitted
fix(compiler): change compiler to support attribute mapping for template decorators
Closes #1581
1 parent c1dd60f commit d658909

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

lib/core_dom/view_factory.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,18 @@ class ViewFactoryCache {
232232
class _AnchorAttrs extends NodeAttrs {
233233
DirectiveRef _directiveRef;
234234

235-
_AnchorAttrs(DirectiveRef this._directiveRef): super(null);
235+
_AnchorAttrs(DirectiveRef directiveRef)
236+
: super(directiveRef.element),
237+
_directiveRef = directiveRef;
236238

237-
String operator [](name) => name == '.' ? _directiveRef.value : null;
239+
String operator [](name) => name == '.' ? _directiveRef.value : super[name];
238240

239241
void observe(String attributeName, _AttributeChanged notifyFn) {
240-
notifyFn(attributeName == '.' ? _directiveRef.value : null);
242+
if (attributeName == '.') {
243+
notifyFn(_directiveRef.value);
244+
} else {
245+
super.observe(attributeName, notifyFn);
246+
}
241247
}
242248
}
243249

test/core_dom/compiler_spec.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ void main() {
5656
..bind(Parent, toValue: null)
5757
..bind(Child)
5858
..bind(ChildTemplateComponent)
59-
..bind(InjectorDependentComponent);
59+
..bind(InjectorDependentComponent)
60+
..bind(TranscludeChildrenWithAttributeDirective);
6061
});
6162

6263
beforeEach((TestBed tb) => _ = tb);
@@ -1149,6 +1150,14 @@ void main() {
11491150
expect(logger).toContain('LazyPane-0');
11501151
}));
11511152
});
1153+
1154+
it('should set attributes on a directive transcluding its children', () {
1155+
_.compile('<div><transclude-children-with-attr attr="value"/></div>');
1156+
_.rootScope.apply();
1157+
1158+
var dir = _.rootScope.context['transclude-children-with-attr'];
1159+
expect(dir.attr).toEqual('value');
1160+
});
11521161
}));
11531162
}
11541163

@@ -1234,6 +1243,20 @@ class SimpleTranscludeInAttachAttrDirective {
12341243
}
12351244
}
12361245

1246+
@Decorator(
1247+
children: Directive.TRANSCLUDE_CHILDREN,
1248+
selector:'transclude-children-with-attr',
1249+
map: const {
1250+
'attr': '@attr'
1251+
})
1252+
class TranscludeChildrenWithAttributeDirective {
1253+
var attr;
1254+
1255+
TranscludeChildrenWithAttributeDirective(RootScope scope) {
1256+
scope.context['transclude-children-with-attr'] = this;
1257+
}
1258+
}
1259+
12371260
@Decorator(selector: '[include-transclude]')
12381261
class IncludeTranscludeAttrDirective {
12391262
IncludeTranscludeAttrDirective(SimpleTranscludeInAttachAttrDirective simple, Logger log) {

0 commit comments

Comments
 (0)