angular - 将数据传递给 Angular ngbModalRef
问题描述
我正在尝试使用 JHipster 学习 Angular。我想使用生成的实体代码弹出窗口(删除实体 - 在我的情况下为 FTPshelf)以不同的方式工作。我希望弹出窗口打印一个动态表单复选框 + auditType entity.name。
无论我做什么它只适用于第一次打开弹出窗口。在我关闭它并再次打开后,实体列表不会填充。
我的代码:
html前端:
<form name="chooseAuditForm" role="form" novalidate (ngSubmit)="audit()" #chooseAuditForm="ngForm"
(change)="chooseAudit(chooseAuditForm)">
<div class="col-lg-12 form-inline" *ngFor="let auditType of auditTypes">
<div class="col-lg-6">{{auditType.name}}</div>
<div class="col-lg-6"><input id={{auditType.id}} type="checkbox" ngModel name="chosenAudit"
class="form-control" value={{auditType}}/></div>
</div>
</form>
ts 组件:
@Component({
selector: 'jhi-ftp-shelf-audit-dialog',
templateUrl: './ftp-shelf-audit-dialog.component.html'
})
export class FtpShelfAuditDialogComponent {
ftpShelf: IFtpShelf;
constructor(private ftpShelfService: FtpShelfService,
public activeModal: NgbActiveModal,
private eventManager: JhiEventManager) {
}
clear() {
this.activeModal.dismiss('cancel');
}
confirmAudit(id: number) {
this.ftpShelfService.delete(id).subscribe(response => {
this.eventManager.broadcast({
name: 'ftpShelfListModification',
content: 'Audit an ftpShelf'
});
this.activeModal.dismiss(true);
});
}
chooseAudit(chooseAuditForm: HTMLFormElement) {
}
}
@Component({
selector: 'jhi-ftp-shelf-audit-popup',
template: ''
})
export class FtpShelfAuditPopupComponent implements OnInit, OnDestroy {
private ngbModalRef: NgbModalRef;
private auditTypes: IAuditType[];
constructor(private activatedRoute: ActivatedRoute,
private router: Router,
private jhiAlertService: JhiAlertService,
private auditTypeService: AuditTypeService,
private modalService: NgbModal) {
}
private onError(errorMessage: string) {
this.jhiAlertService.error(errorMessage, null, null);
}
ngOnInit() {
this.getAuditTypes();
this.activatedRoute.data.subscribe(({ftpShelf}) => {
setTimeout(() => {
this.ngbModalRef = this.modalService.open(FtpShelfAuditDialogComponent as Component, {
size: 'lg',
backdrop: 'static'
});
this.ngbModalRef.componentInstance.ftpShelf = ftpShelf;
this.ngbModalRef.componentInstance.auditTypes = this.auditTypes;
this.ngbModalRef.result.then(
result => {
this.router.navigate([{outlets: {popup: null}}], {
replaceUrl: true,
queryParamsHandling: 'merge'
});
this.ngbModalRef = null;
},
reason => {
this.router.navigate([{outlets: {popup: null}}], {
replaceUrl: true,
queryParamsHandling: 'merge'
});
this.ngbModalRef = null;
}
);
}, 0);
});
}
getAuditTypes() {
this.auditTypeService.query().subscribe(
(res: HttpResponse<IAuditType[]>) => {
this.auditTypes = res.body;
},
(res: HttpErrorResponse) => this.onError(res.message)
);
}
ngOnDestroy() {
this.ngbModalRef = null;
}
}
我做错了什么?我知道我应该以其他方式填充变量 auditTypes 但没有想到。感谢您提前回答。
解决方案
我想到了。我移动了
this.ngbModalRef.componentInstance.auditTypes = this.auditTypes;
就在 this.getAuditTypes 下
推荐阅读
- html - 在分层图像上放置文本
- azure-functions - 是否可以使用功能密钥在 Azure AD B2C 用户旅程中保护 Azure 功能
- node.js - 动态地将名称从表传递到函数定义
- java - 在不使用spring security的情况下在spring boot中获取静态资源的403
- django - 如何过滤我在 ModelChoiceField 字段中使用的查询集?
- php - 导入带有负数但减号是最后一个字符的 txt 文件
- swift - CocoaPods deintegrate 删除工作区文件
- node.js - 提高http请求响应时间
- pandas - 突出 matplotlib 中的政权变化
- java - 如何使用 Stream 填充矩阵?