Answer the question
In order to leave comments, you need to log in
Why does DragDrop work in one component and not in another?
I have a component like this:
import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { OrderApplicationUI } from '../../models/application.list.model';
import { ListService } from '../../services/sorting.service';
@Component({
selector: 'app-order-applications-list',
templateUrl: './order-applications-list.component.html',
styleUrls: ['./order-applications-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [ListService],
})
export class OrderApplicationsListComponent implements OnInit {
@Input() applications: OrderApplicationUI[] = [];
@Output() onSelected = new EventEmitter<OrderApplicationUI[]>();
constructor(private listService: ListService) {}
ngOnInit(): void {
this.listService.setItems(this.applications);
}
public drop(event: any): void {
this.listService.drop(event);
}
public select(app: OrderApplicationUI): void {
app.selected = !app.selected;
this.onSelected.emit(this.applications.filter((app) => app.selected));
}
}
<div cdkDropList class="order__application__list" (cdkDropListDropped)="drop($event)">
<div
class="order__application__list__item"
[ngClass]="{ order__application__list__item_selected: app.selected }"
*ngFor="let app of applications; let i = index"
(click)="select(app)"
cdkDrag
>
<div class="example-custom-placeholder" *cdkDragPlaceholder></div>
{{ app.value }}
</div>
</div>
<div class="nodata" *ngIf="!applications || applications.length == 0">Нет данных</div>
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { OrderApplicationsListComponent } from './order-applications-list.component';
import { DragDropModule } from '@angular/cdk/drag-drop';
@NgModule({
imports: [CommonModule, DragDropModule],
declarations: [OrderApplicationsListComponent],
exports: [OrderApplicationsListComponent],
})
export class OrderApplicationsListModule {}
<app-order-applications-list [applications]="block?.datasource?.value"></app-order-applications-list>
<div cdkDrag cdkDragLockAxis="x">
I'm Draggable
</div>
Answer the question
In order to leave comments, you need to log in
Oh, such things are difficult to analyze without having working code on hand. You say it works:
<div cdkDrag cdkDragLockAxis="x">
I'm Draggable
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question