2
I’m doing an angled drag & drop, but one of the rules I need in the application is that the item stays in the same place after the page is reloaded. Something more or less like the image.
HTML code:
<div
#pieElement
*ngIf="equipment"
cdkDragBoundary=".content"
cdkDrag
(cdkDragEnded)="dragEnd($event)"
(cdkDragEntered)="dragEnter($event)"
[chart]="pie"
[ngClass]="active ? 'pie' : 'pie-inactive'"
[style.transform]="transform"
></div>
On the controller startup:
ngOnInit() {
...
this.transform = "";
this.transform = localStorage.getItem(`${this.serialnumber}`);
...
}
Funcão Dragend:
dragEnd(event: CdkDragEnd) {
let position = event.source.element.nativeElement.style.transform;
localStorage.setItem(`${this.serialnumber}`, position);
}
How can I develop this Feature? Every time the dragend function is called, because of the angular CDK, a new Transform is set to the element.
I’m trying to implement your suggestion, but by putting Input
[cdkDragFreeDragPosition]
. I have this error on the console:Template parse errors:
Can't bind to 'cdkDragFreeDragPosition' since it isn't a known property of 'div'. ("
– Matheus Bernardi
@Matheusbernardi now I don’t know hem! You even imported in the module of your component the reference
import {DragDropModule} from '@angular/cdk/drag-drop';
? this property is listed in the documentation itself and there they give an example of how to use it: https://stackblitz.com/angular/aejyednlgvk?file=.angular-cli.json Please try checking the version. This code is directed with @angular cdk 8.2.1– Marcelo Vismari
It worked! I upgraded my version of angular and managed to use cdk
– Matheus Bernardi
According to the package.json file of the CDK repository, version 8.2.x depends on Angular 8.2.x in the same way that CDK 9 depends on Angular 9.
– Marcelo Vismari