Angular 2 Component - Access DOM (or create Component without template, purely from JS)

后端 未结 5 1287
滥情空心
滥情空心 2021-02-05 06:41

Trying to play with Angular 2 here... understood that it\'s still in alpha.

How do I access DOM elements from Component? Specifically, I would like to use other librarie

5条回答
  •  旧巷少年郎
    2021-02-05 07:01

    As other posters have mentioned: you can manipulate the DOM by injecting ElementRef into the directive. However, consider carefully whether you really need to do this.

    D3 is a DOM manipulation tool. It allows you to bind a data object to a DOM node, then add or remove child elements from that element in response to changing data values. This is pretty much exactly what Angular 2 does.

    Of course, D3 does other things as well. You can generate angles for a pie chart, or a normal distribution for example, and you may wish to use D3 for this.

    I know it's not the answer you're looking for. It's not the answer I was looking for, but... Consider carefully whether you need to use D3 for DOM manipulation and data binding. Angular 2 already has DOM manipulation and data binding.

提交回复
热议问题