An Easy way to Create a Draggable & Resizable Angular Component
You can achieve the draggable and resizable component yourself without Angular Material. You need to do it in three steps.
- Make a div resizable
- Link mouse movement to the div’s position to make it draggable/movable
- Add boundary restrictions to your mouse movements
The core of step (1) is to calculate the new div size by subtract mouse position(coordinates) and div’s position(left&top positions)
Step (2) requires calculating the movement of your mouse and add the same amount of movements to your div’s top & left position.
Step (3) you will need to calculate the outside container’s top, right, bottom and left boundaries’ position.
To get div element’s position, you need to use Web API - Element.getBoundingClientRect()
To get mouse positions you need to add a mouse move listener to the window and a mouse down listener to the div element itself.
I have written a post about how to achieve these three steps with further explanations and graphics. You can have a look if you are still not clear about how to achieve it.
Create a Resizable and Draggable Angular Component