这就是我使用 ng2-bootstrap 模式的方式:
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);
});
}
}
我有点困惑,因为我认为内容是用来向模态传递参数的。但在我看来,它只是打开方法需要找到正确模板的名称吗?
那么如何传递参数呢?