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?
}
}