我需要你的帮助。我不知道如何传递在模态中编辑的数据。
cohorts.component.html ...
<button class="btn btn-success btn-lg" type="button" (click)="addCohorte(content)">+Add Cohort</button>
<br>
这是cohorts.component.ts
updateCohorte(content, cohort: Cohorte): void {
console.log(this.data)
this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
this.cohorteService.updateCohorte(cohort, result).subscribe(
res => this.getCohortes()
);
}, (reason) => {
});
我的模态内容组件
modal-content-component.ts
import {Component, Input} from "@angular/core";
import {NgbActiveModal} from "@ng-bootstrap/ng-bootstrap";
@Component({
selector: 'ngbd-modal-content',
template: `
<div class="modal-header">
<h4 class="modal-title">Hi there!</h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="activeModal.close('Close click')">Close</button>
</div>
`
})
export class NgbdModalContent {
@Input() firstName;
@Input() lastName;
@Input() minimumBreakTime;
constructor(public activeModal: NgbActiveModal) {}
}
还有我的cohort.service.ts
...
updateCohorte(cohort: Cohorte, data: any): Observable<Cohorte> {
let url = this.UPDATE_COHORTE + '/' + cohort.id;
return this.http.put<Cohorte>(url, data)
}
}