dart - Scoping issues when rendering transcluded content with <content> -
i'm trying make simple component display loading screen until data has arrived , provide simple error handling:
<loading done="ctrl.dataloaded" error="ctrl.dataerror"> <graph width="ctrl.graphwidth" data="ctrl.data"> </graph> </loading>
the template <loading>
looks this:
<div ng-switch="cmp.error"> <div ng-switch-when="null"> <div ng-switch="cmp.done"> <div ng-switch-when="false"> <h1>loading, please wait...</h1> </div> <div ng-switch-default> <content></content> </div> </div> </div> <div ng-switch-default> <h1>an error occurred: {{cmp.error}}</h1> </div> </div>
however, transcluded <graph>
component sees null on attributes instead of expected data controller, failing render.
i assume because it's rendered in scope of <loading>
, original ctrl
binding not available anymore? there way around this, preserving original attribute bindings?
edit: mentioned in comment below, problem seems come combination of transclusion <content>
, having component receives data on attributes. transcluding simple values {{ctrl.graphwidth}}
works fine.
edit2: requested, controller
@ngcontroller( selector: '[some-graph]', publishas: 'ctrl') class somegraphcontroller implements ngattachaware { bool dataloaded = false; string dataerror = null; int graphwidth = -1; list<point> data; void attach() { requestdata().then((d) { data = d; dataloaded = true; }).catcherror((e) => dataerror = e.tostring()); } }
and chart component
@ngcomponent( selector: 'graph', template: "<svg id='chart'></svg>", cssurl: '/graph.css', publishas: 'cmp') class graphcomponent implements ngshadowrootaware { @ngoneway('width') int width; @ngoneway('data') list<point> data; void onshadowroot(shadowroot shadowroot) { print('displaying $data'); drawgraph(shadowroot.queryselector("#chart")); } }
the print statement prints 'displaying null' when graph component used within loading component, correctly prints data assigned controller when used outside.
i don't think scoping issue.
tried reproduce without ng-switch tags , graph got value controller applied ancestor of <loading>
.
Comments
Post a Comment