gpt4 book ai didi

angular - ng2-dragula [dragula](angular2 拖放)- *ngFor with [dragulaModel] 属性不起作用

转载 作者:太空狗 更新时间:2023-10-29 17:24:47 25 4
gpt4 key购买 nike

为 Angular 2 dragula 使用 ng2-dragula 拖放包装器库。

https://github.com/valor-software/ng2-dragula

看到 [dragulaModel]='myList' ... 的问题,当项目被丢弃时... ...它消失了。

检查该元素,我看到它保留在模型中,但 DOM 元素丢失了它的 inner html(变成空的 div)——导致 div“看起来”被隐藏了。

import { Component } from '@angular/core';
import { DragulaService } from 'ng2-dragula/ng2-dragula';

@Component({

moduleId: module.id,
selector: 'my-app',
template: `
<div>
<div class='wrapper'>
<div class='container' *ngFor='let fixture of fixtures' [dragula]='"first-bag"' [dragulaModel]='fixtures'>
<div>{{fixture.name}}</div>
</div>
</div>
</div>
`,
viewProviders: [DragulaService],
styles: [`
.wrapper {
display: table;
}
.container {
display: block;
background-color: rgba(255, 255, 255, 0.2);
width: 200px;
}
.container div,
.gu-mirror {
margin: 10px;
padding: 10px;
background-color: rgba(0, 0, 0, 0.2);
transition: opacity 0.4s ease-in-out;
}
.container div {
cursor: move;
cursor: grab;
cursor: -moz-grab;
cursor: -webkit-grab;
}
.gu-mirror {
cursor: grabbing;
cursor: -moz-grabbing;
cursor: -webkit-grabbing;
}
`]

})
export class DragulaComponent {
fixtures: any[];

constructor( private dragulaService: DragulaService ) {
dragulaService.dropModel.subscribe((value:any[]) => {
console.log(value);
console.log(this.fixtures[0]);
});
}

ngOnInit(): void {
this.fixtures = [
{ id: 11, name: 'Table 1', day: 1, duration: '4h', closetBuild: true, clearance: false, consolidateExpand: '', associateMoves: 'dan', notes:'blah blah blah.', items: [ {name: "christmas sweaters", skus: [{sku:'123', comingFrom:'test coming from', earlySet: false}] }] },
{ id: 12, name: 'Table 2', consolidateExpand:'', duration: '1.5H'},
{ id: 13, name: 'Table 3 / C5', consolidateExpand:'e', day: 99, duration: '99.99h', },
{ id: 14, name: 'Table 4', day: 1 },
{ id: 15, name: 'Closet 70-71', day: 1, duration: '19h', closetBuild: false, clearance: false, consolidateExpand:'e', items: [ {name: "christmas sweaters and other very cool stuff", skus: [{sku:'123-456-789-111', comingFrom:'blah blah blah coming from', earlySet: 'fixtures'},{sku:'123-aaaa-383838383838-1', comingFrom:'test coming from'}] }] },
{ id: 16, name: 'Closet 77-78' },
{ id: 17, name: 'Closet 80-81' },
{ id: 18, name: 'Closet 82-83' },
{ id: 19, name: 'BACKSTOCK' },
{ id: 20, name: 'TABLE C1' }
];
}
}

最佳答案

好吧,问题解决了。内部 html 是空白的,因为 dragula 移动的实际 DOM 元素是内部 html(元素的内容),而不是移动标有属性 [dragula] 的元素。

这修复了它:

    <div class='wrapper' [dragula]='"first-bag"' [dragulaModel]='fixtures'>
<div class='container' *ngFor='let fixture of fixtures'>
<div>{{fixture.id}}</div>
</div>
</div>

他们自己的文档对此有点不清楚,因为他们有:

<ul>
<li *ngFor="let item of items" [dragula]='"bag-one"' [dragulaModel]='items'></li>
</ul>

故事的寓意:将您的 [dragula][dragulaModel] 从您放置 *ngFor 的位置向上移动一个元素。

关于angular - ng2-dragula [dragula](angular2 拖放)- *ngFor with [dragulaModel] 属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41044832/

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