本文介绍了NgComponent就绪事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个 NgComponent
,当组件加载时,它填充了元素。如何知道组件何时被模板填充?这是我的一些代码:
I am trying to create a NgComponent
which is populated with elements when the component is loaded. How do I know when the component is populated with the template? Here is some of my code:
class SleepTimeModule extends Module {
SleepTimeModule() {
//...
type(SleepGraph);
//...
}
}
//...
@NgComponent(
selector: 'sleep-graph',
publishAs: 'sleepGraph',
template: '<div><svg></svg></div>'
)
class SleepGraph {
Element element;
Scope scope;
@NgTwoWay('data')
var data;
SleepGraph(this.element, this.scope);
// when can I call this method?
// it modifies the dom
drawChart(data){
js.context.callMethod("drawChart", [
element.shadowRoot.querySelector("svg"),
new js.JsObject.jsify(data)
]);
}
}
推荐答案
NgShadowRootAware
的 onShadowRoot
方法,如下所示:
//...
class SleepGraph implements NgShadowRootAware {
//...
// This method is called when the dom is ready
void onShadowRoot(ShadowRoot shadowRoot){
}
}
已经有类似的问题:
- AngularDart NgComponent using event listeners in the controller
- How to add a component programatically in Angular.Dart?
这篇关于NgComponent就绪事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!