NgComponent ready event

*爱你&永不变心* 提交于 2019-12-24 23:14:31

问题


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)
    ]);
  }
}

回答1:


Implement NgShadowRootAware's onShadowRoot method, like this:

//...
class SleepGraph implements NgShadowRootAware {
    //...
    // This method is called when the dom is ready
    void onShadowRoot(ShadowRoot shadowRoot){

    }
}

There are already similar questions:

  • AngularDart NgComponent using event listeners in the controller
  • How to add a component programatically in Angular.Dart?


来源:https://stackoverflow.com/questions/22103804/ngcomponent-ready-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!