1

I am testing the HTML5 drag and drop with the Angular application. Just wondering what is wrong here. I have the below code in the app.component.html file.

<div>
  <p draggable="true" ondragstart="drag(event)">Coffee</p>
</div>

And I have this in the Typescript file app.component.ts

export class AppComponent {

 function drag(ev) {
    console.log(ev);
  }
}

It says reference error in the console of the browser. Why is it not outputting anything on the console? Please advise!

4
  • 2
    Use angular way of events replace ondragstart with (dragstart) Commented Dec 19, 2017 at 5:56
  • Where do I find the Angular events? Any links? Commented Dec 19, 2017 at 5:57
  • 1
    It has all the supported events by html just remove on from event and surround with () example for onclick it is (click) ,onsubmit is (submit) Commented Dec 19, 2017 at 6:00
  • Any custom event or dom event is captured with a (eventwithouton) . Check angular getting started in the angular.io site Commented Dec 19, 2017 at 6:03

1 Answer 1

2

In angular2/4/5/6/7/8 replace (onevents) with (events) see the example below

ondrop with (drop)

ondragover with (dragover)

ondragstart with (dragstart)

Sign up to request clarification or add additional context in comments.

1 Comment

Took me a day to figure out what's wrong and you saved me, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.