[英]Using a ngx-smart-modal, how to only evaluate modal content, when it is shown
I am developing an angular app. 我正在开发一个有角度的应用程序。 In this app you can create some sort of support tickets.
在此应用中,您可以创建某种形式的支持通知单。 When the user is done creating the ticket and clicks the send button I am showing a modal that has all the provided information.
当用户完成创建票证并单击“发送”按钮后,我将显示具有所有提供的信息的模式。 The modal is a ngx-smart-modal with customClass set to the bootstrap modal.
模态是ngx-smart-modal,其中customClass设置为bootstrap模态。
After sending the ticket I reset the whole form. 发送票证后,我重置了整个表格。 Now it seems like the content of the modal is being evaluated even if it is not shown, which results in 'ERROR TypeError: Cannot read property 'name' of null' errors, since those fields are reset.
现在看来,即使未显示模态的内容也正在评估中,这会导致“错误TypeError:无法读取属性'name'of null'”错误,因为这些字段已重置。
Is there a way to only evaluate the modal contents when it is shown? 有没有办法只显示模态内容?
I tried to do something like this: 我试图做这样的事情:
<p>Category: {{selectedCategory ? selectedCategory.name : ''}}</p>
Which works, but I am unsure if this is a good approach? 哪个可行,但是我不确定这是否是一个好方法?
My modal: 我的模态:
<ngx-smart-modal #confirmSendTicket identifier="confirmSendTicket" [customClass]="'modal-body'">
<div style="text-align: left">
<h3>Send ticket?</h3>
<span>
<p>Caller:</p>
<p>Section: {{selectedSection ? selectedSection.name : 'N/A'}}</p>
<p>Lastname: {{this.lastname || 'N/A'}}, Firstname: {{this.firstname || 'N/A'}}, Phone
{{this.phone || 'N/A'}}</p>
<p>Category: {{selectedCategory.name}}</p>
<p>Issue: {{selectedIssuesubject.name}}</p>
<p *ngFor="let field of ticketissuesubjectFields">{{field.name + ': '}} <br /> {{field.content}}</p>
<p>Ticketinformation:</p>
<p>Title: {{emailSubject.value}}</p>
<p>Description: <br />{{descriptionText.value}}</p>
<p>Solution: <br />{{solution.value || 'N/A'}}</p>
<p>Problem solved: {{solved.value ? 'Yes' : 'No'}}</p>
<p *ngIf="!solved.value">Info: <br />{{info.value}}</p>
<p>Start date: {{selectedStartDate.value.toLocaleString()}}</p>
<p>End date: {{selectedEndDate.value.toLocaleString()}}</p>
<p>Assessment: {{selectedAssessment.value.name}}</p>
<p>Sending mails to: <br /></p>
<p *ngFor="let user of selectedEmailUsers">{{user.lastname + ', ' + user.firstname}} <br /></p>
</span>
</div>
<div class="row">
<div class="col-md-6">
<button type="button" (click)="onConfirmSendTicket()" class="btn btn-block btn-success">Send</button>
</div>
<div class="col-md-6">
<button type="button" (click)="onReject()" class="btn btn-block btn-dark">Cancel</button>
</div>
</div>
</ngx-smart-modal>
You can make the data's interpretation optional with the safe navigation operator like : {{ selectedSection?.name }}
您可以使用诸如
{{ selectedSection?.name }}
这样的安全导航运算符来使数据的解释为可选。
If you want to display an alternative string, you can use a hydrator to check the data before injecting it into your view : 如果要显示替代字符串,可以使用水化器检查数据,然后再将其注入视图:
hydrateSection(data) {
return { name: data.name || 'N/A' };
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.