gpt4 book ai didi

angular - 模板解析错误 : There is no directive with "exportAs" set to "cdkDropList"

转载 作者:行者123 更新时间:2023-12-04 17:06:27 25 4
gpt4 key购买 nike

我正在尝试使用 Angular Material 进行拖放,如 Transferring items between lists 中所示.

我正在尝试与示例中显示的完全相同的代码,但在控制台中出现此错误:

Uncaught Error: Template parse errors: There is no directive with "exportAs" set to "cdkDropList"



以下是我的代码,与链接中显示的相同,无论如何我都在分享:

客服:
import {Component} from '@angular/core';
import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop';

/**
* @title Drag&Drop connected sorting
*/
@Component({
selector: 'cdk-drag-drop-connected-sorting-example',
templateUrl: 'cdk-drag-drop-connected-sorting-example.html',
styleUrls: ['cdk-drag-drop-connected-sorting-example.css'],
})
export class CdkDragDropConnectedSortingExample {
todo = [
'Get to work',
'Pick up groceries',
'Go home',
'Fall asleep'
];

done = [
'Get up',
'Brush teeth',
'Take a shower',
'Check e-mail',
'Walk dog'
];

drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex);
}
}
}

HTML:
<div class="example-container">
<h2>To do</h2>

<div
cdkDropList
#todoList="cdkDropList"
[cdkDropListData]="todo"
[cdkDropListConnectedTo]="[doneList]"
class="example-list"
(cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let item of todo" cdkDrag>{{item}}</div>
</div>
</div>

<div class="example-container">
<h2>Done</h2>

<div
cdkDropList
#doneList="cdkDropList"
[cdkDropListData]="done"
[cdkDropListConnectedTo]="[todoList]"
class="example-list"
(cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let item of done" cdkDrag>{{item}}</div>
</div>
</div>

最佳答案

API 中所述您需要导入 DragDropModule在你的模块中

import {DragDropModule} from '@angular/cdk/drag-drop';

@NgModule({
...
imports: [
...
DragDropModule
...

关于angular - 模板解析错误 : There is no directive with "exportAs" set to "cdkDropList",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55432756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com