這是我使用NG2的自舉模式的方法:如何將參數傳遞給模態?
import {Component} from '@angular/core';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'add-customer-modal',
template: `
<template #test let-c="close" let-d="dismiss">
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="c('Close click')">Close</button>
</div>
</template>
<button type="button" class="btn btn-primary btn-sm" (click)="open(test)"><i class="fa fa-plus"></i> <i class="fa fa-user-o"></i></button>
`
})
export class AddCustomerModal {
constructor(private modalService: NgbModal) {}
open(content) {
this.modalService.open(content, { size: 'lg' }).result.then((result) => {
console.log(result);
}, (reason) => {
console.log(reason);
});
}
}
我'有點困惑,因爲我認爲內容是用來傳遞參數模式。但在我看來,這只是開放方法需要找到正確模板的名稱?
那麼我該如何傳遞參數?
在這裏閱讀更多信息:[http://stackoverflow.com/questions/39464345/best-practice-for-calling-the-ngbmodal-open-method](http://stackoverflow.com/questions/39464345 /最佳實踐調用ngbmodal開放方法) – PierreDuc
@PierreDuc謝謝!我怎樣才能將參數/數據傳遞給模態? – robert