我正在使用ng2-dragula进行项目,而在拖放drop
时,模型更新不起作用<ul style="list-style-type: none;">
<li *ngFor="let item of itemList" [dragula]='"bag-one"' [dragulaModel]='itemList' >
<div >
{{item.label | itemFilter:user.language}}
<a (click)="delete(item)" style="cursor:pointer;">delete</a>
</div>
</li>
</ul>
我组件的一部分:
@Component({
moduleId: module.id,
selector: 'item-user',
templateUrl: 'item.component.html',
styleUrls: ['item.component.css'],
pipes: [itemFilter],
directives: [Dragula]
...
我的根组件的一部分
@Component({
.....
viewProviders: [DragulaService]
拖放效果正常,放置项目列表(模型)未更新(控制台没有错误)为什么?
您需要将Dragula指令移至"袋子"级别。
<ul style="list-style-type: none;" [dragula]='"bag-one"' [dragulaModel]='itemList'>
<li *ngFor="let item of itemList">
...
对我而言,它不起作用,因为我将dragula放在正在转换为Shadow dom的HTML元素上。
例如,我从中走了:
<ion-card-content dragula="DRAGULA_FACTS">
<ion-item *ngFor="let featureUserType of featureUserTypes">
<uab-menu-feature-button [feature]="featureUserType"
[enableRoutes]="false"
[showDescription]="true"
[showFullName]="true"></uab-menu-feature-button>
</ion-item>
:
<div [dragula]="'REORDER_FEATURES'"
[dragulaModel]="featureUserTypes"
(dragulaModelChange)="reorderFeatures($event)">
<div *ngFor="let featureUserType of featureUserTypes">
<ion-item>
<uab-menu-feature-button [feature]="featureUserType"
[enableRoutes]="false"
[showDescription]="true"
[showFullName]="true"></uab-menu-feature-button>
</ion-item>
</div>
</div>