Reputation: 1402
I have a typescript code with simple if else logic
endDate: String = '';
customerStatus: String;
this.endDate = this.sampleData.customerStartDate;
if (this.endDate == null) {
this.customerStatus = 'Active';
} else {
this.customerStatus = 'In Active';
}
HTML Code:
<div class="col-md-3">
<div class="card-counter info">
<i class="fa fa-refresh"></i>
<span class="count-numbers">
<h4 class="margin">{{customerStatus}}</h4></span>
<span class="count-name"> Customer Status</span>
</div>
</div>
</div>
If I debug the code then in endDate I can see the value but in CustomerStatus I am getting Undefined and as a result, nothing is being displayed on HTML. The logic is if the customer has end date then the customer is In-Active or else the customer is Active What am I doing wrong?
Upvotes: 0
Views: 48
Reputation: 18975
You did not check null
for sampleData
object before using customerStartDate
property.
Because line of code this.sampleData.customerStartDate
throw exception, the next line of code cant executed.
Edit this line of code, it worked.
this.endDate = this.sampleData != null ? this.sampleData.customerStartDate : null;
https://stackblitz.com/edit/angular-wefvju
Upvotes: 2