我有一个文件上传表和一个带有innerHTML属性绑定的空div.当用户上传一个文件(EXCEL)时,它将被服务器处理,转换成html并存储在数据库中.然后,Angel将从数据库中获取数据,对其进行清理(这样就不会删除CSS样式),并通过innerHTML属性绑定将其插入到空div中.
问题是,在文件上传之后,如果不重新加载页面,它不会更新div的内容.我想在不重新加载页面的情况下更新<div *ngIf="budgetHTML" [(innerHTML)]="budgetHTML"></div>
.
我是个新手,有什么建议可以让我做到这一点吗?
component.html
<div *ngIf="budgetHTML" [(innerHTML)]="budgetHTML">
</div>
Component.ts(我只包含了相关代码)
export class ProgramProjectInformationComponent implements OnInit, OnDestroy {
budgetHTML: SafeHtml;
constructor(
private store: Store<AppStateInterface>,
private formBuilder: UntypedFormBuilder,
private grantProposalService: GrantProposalService,
private route: ActivatedRoute,
private sanitizer: DomSanitizer,
) {}
ngOnInit(): void {
this.initializeForm();
this.initializedValues();
this.initializePdoPrograms();
this.initializePdoBankAccounts();
this.intializeListeners();
this.initializeBudgetTable();
}
initializedValues() {
this.grantProposalData$ = this.store.pipe(select(grantProposalSelector));
this.isLoading$ = this.store.pipe(select(isFetchingGrantProposalSelector));
this.composeBankAccount$ = this.store.pipe(select(grantProposalComposeBankAccountSelector));
this.grantProposalDraftStatus$ = this.store.select(grantProposalDraftStatusSelector);
}
initializeBudgetTable() {
this.grantProposalData$
.pipe(
takeUntil(this.destroy$)
)
.subscribe(data => {
this.budgetHTML = this.sanitizer.bypassSecurityTrustHtml(data?.budget_info);
});
}
/**
* for importing budget data to database
*
* @return void
*/
importBudget() {
this.loadingUpload = true;
if (this.budgetForm.valid) {
// convert formControl to FormData to allow sending images/files
let formData = this.convertToFormData();
this.grantProposalId$.pipe(takeUntil(this.destroy$)).subscribe(id => {
formData.set('grant_proposal_id', id);
});
this.grantProposalService
.importBudgetTable(formData)
.pipe(
takeUntil(this.destroy$)
)
.subscribe({
next: (res) => {
this.showAlertDataSaved(res.results.message);
this.initializedValues();
this.initializeBudgetTable();
},
error: (err) => {
this.showAlertSavingFailed(err.error.message);
this.loadingUpload = false;
},
complete: () => {
this.loadingUpload = false;
}
})
} else {
this.loadingUpload = false;
this.showAlertCheckFields('Please fill in the required fields to proceed.');
}
}
}