【发布时间】:2020-10-07 00:15:20
【问题描述】:
我正在使用 Angular Material 的 Drag and Drop Module。 cdkDrag 似乎无法与 span 和我观察到的其他几个标签一起使用,例如 a 标签。
component.html
<div class='user' *ngFor='let user of usersTask; let i = index'>
User: {{i}}
<span class='task' *ngFor='let task of user' cdkDropList cdkDrag>
{{task}}
</span>
</div>
component.ts
import { Component } from '@angular/core';
@Component({
selector: 'some-root',
templateUrl: './some.component.html',
styleUrls: ['./some.component.scss']
})
export class SomeComponent {
usersTask = [[
'Get to work',
'Pick up groceries',
'Go home',
'Fall asleep'
],[
'Get up',
'Brush teeth',
'Take a shower',
'Check e-mail',
'Walk dog'
]];
}
但是,如果我将 span 替换为 div 标记,它会起作用。
任何想法,为什么会发生这种情况?以及如何解决这个问题?
提前致谢!
【问题讨论】:
-
你需要一个 cdkDragList 和不同的 cdkDrag 里面的 cdkDragList -不能是同一个标签 -
-
没看懂,能多解释一下吗,举几个例子?
-
你在
<span cdkDropList cdkDrag>,我想你想要<div *ngFor=".." cdkDropList><span *ngFor=".." cdkDrag>(我把答案放在了)
标签: angular typescript angular-material angular-cdk angular-cdk-drag-drop