0

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)
    ]);
  }
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0xcaff
  • 13,085
  • 5
  • 47
  • 55

1 Answers1

0

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:

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567