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

回答

1

我仍然不知道爲什麼會這樣。但我解決了這個問題,通過將2個自引導可排序組件包裝到您自己的組件MySortableComponent中,該組件具有可排序組件。