1
我有一個按鈕採用NG-引導模式模式NG的自舉與排序組件從NG2的自舉
<button (click)="openModal()">Open</button>
裏面排序組件modal.html的模板是觸發模式整合:
<template #modalContent let-c="close" let-d="dismiss">
<bs-sortable #sortableComponent [(ngModel)]="array
[itemTemplate]="itemTemplate"></bs-sortable>
</template>
<template #itemTemplate let-item="item" let-index="index">
<div>{{item | json}}
<span class="fa fa-trash" (click)="removeItem(array,index)"></span>
</div>
</template>
類將是:
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
export class sortableModal{
@Input() public array: [];
@ViewChild("modalContent") public modalContent: NgbModalModule;
@ViewChild("sortableComponent") sortableComponent: SortableComponent;
constructor(public modalService: NgbModal){
}
openModal(){
this.modalService.open(this.modalContent);
}
removeItem(arr,i){
if(i===undefined) i = -1;
arr.splice(i,1);
this.sortableComponent.writeValue(arr);
//this.sortableComponent is undefined; why is that?
}
}