Search code examples
javascriptdartangular-dart

Obtain component id from javascript


In dart we can obtain dom element through 'querySelector' method. But I need a reverse kind method: insert data into "dart component" element from Javascript. Is there a way to achieve that?

I have try:

html file:

<comp></comp>
<script>
  document.getElementById('mydiv').text = "HELLO";
  document.getElementById('myd').text = "HELLO";
</script>

dart component:

@Component (
  selector: 'comp',
  template: '<div #mydiv id="myd">12345</div>',
)
class ModelerComponent {

PS: I need that because my js library requires element id, and there is no option to port it.


Solution

  • Thanks to comments, I've solve the problem: I place code which initializes JS library into ngOnInit() method of a component. So the js library is initialised right after an angular component.