我需要在列表中删除值之前,用 Angular2-multiselect
. 我在下面解释我的代码。
<div class="form-field">
<angular2-multiselect [data]="searchCoupon" #ProductCoupon formControlName="couponValues" [settings]="settings">
<c-search>
<ng-template>
<input type="text" (keyup)="onCouponSearch($event)" placeholder="Search coupons" style="border: none;width: 100%; height: 100%;outline: none;"/>
</ng-template>
</c-search>
<c-item>
<ng-template let-item="item">
<label style="color: #333;">{{item.CouponCode}}</label>
</ng-template>
</c-item>
<c-badge>
<ng-template let-item="item">
<label style="margin: 0px;">{{item.CouponCode}}</label>
<mat-icon matSuffix (click)="editCoupon(item._id,true)" style="font-size: 17px;width: 15px;padding-left:5px;color:white">edit</mat-icon>
</ng-template>
</c-badge>
</angular2-multiselect>
</div>
这里我使用了 Angular-multiselect
通过搜索从列表中选择多个项目,这部分工作正常。在这里,我需要当用户要删除任何选中的项目时,如果用户点击一个javascript提示,将首先显示 ok
按钮,那么选中的项目就会被删除,否则就不会从列表中删除。
为了达到这个目的,你需要使用 confirm(args)
其中返回一个 boolean
当用户点击ok时为true,当用户点击cancel时为false。
你可以这样使用它。
const isOkDelete: boolean = confirm('Are you sure you want to remove this item?');
if (isOkDelete) {
// delete this item...
} else {
// do not delete this item...
}