0

I want to create miller columns in angular 4. It can have any level of columns based on the input. And items from one column can be dragged and dropped in other columns.

My problem is attaching events for dynamically created elements in angular4. Like below code in jquery

 $('.parentConstantDiv').on('click','.dynamicallyCreatedDiv',function(){
   //Some task here
 })

I could have used angular renderer but it allows to attach events only to window, document and body. But thats not jQuery handler mentioned above does.

Can someone help me to create handler like jQuery handler mentioned above in angular 4 component.

I got this pure java script method answer, but events are not removed when element is deleted from DOM.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pradeep
  • 140
  • 9
  • you can use `(click)` dont use `jquery` – Sravan May 23 '18 at 07:56
  • I want to attach multiple events like dragstart, dragover, dragenter, drop etc. So attaching events in html is not nice method is what I feel. And I do not want to use jQuery. That is why I have posted this question. – Pradeep May 23 '18 at 08:40
  • 1
    Attaching event via html still is the angular way if doing it. Maybe use a drag-and-drop library (like https://github.com/akserg/ng2-dnd) to support all these kind of events without so much html verbosity. – Capricorn May 23 '18 at 09:09
  • @Capricon, Thanks buddy. But there isn't a way to handle events the way I asked in the question? – Pradeep May 23 '18 at 09:17
  • You need to share full code of your implementation as of now it is too unclear what exactly you want and how that is supposed to work. Like is it a grid or not, do you need mouse AND touch or not etc etc – Sergey Rudenko Jun 01 '18 at 00:30
  • @SergeyRudenko To make question simple I want replicate the jquery code to angular4 code. Rest everything I am able to do. – Pradeep Jun 01 '18 at 07:28

1 Answers1

0

Though I did not find exact answer to replicate the jQuery code in the question, I got something similar solution using this dynamic dom adding method.

Posting this answer so it might help someone else. Cheers!

Pradeep
  • 140
  • 9