Jorgen Timarey
Jorgen Timarey

Reputation: 147

import custom javascript in angular

How to import https://anseki.github.io/plain-draggable/ in angular ?

I've npm i plain-draggable then import in angular.json the .min.js

In html

  <span id="draggable" style="background-color: lightskyblue;">adipiscing</span>
  elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
  enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
  aliquip ex ea commodo consequat.</p>

And in component : declare const PlainDraggable: any;

then called in constructor PlainDraggable()

I get the error Cannot call a class as a function

Upvotes: 4

Views: 447

Answers (1)

Tolga Yiğit
Tolga Yiğit

Reputation: 434

Instead of calling it on your constructor, try calling it on your AfterViewInit hook like this:

ngAfterViewInit() {
    const draggable = new PlainDraggable(document.getElementById('draggable'));
}

Upvotes: 4

Related Questions