2

I am displaying a grid of employees as below

 <ion-row *ngFor="let employee of employees; let i = index ">

I am calculating the total salary using a custom pipe as per below:

<div class="tot-salary">
 Total Salary: {{employees | returntotal: 'sal' | number:'.2-2'}}
</div>

When component variable 'employees' is updated with a new employee, a new row is created for the employee but the total salary is not updated. It seems it is not detecting any change in employees for the total salary.

Thanks for helping.

Ashley

ashley
  • 1,008
  • 17
  • 37
  • 1
    Can you add the code where you are adding new employee? – yurzui Mar 30 '17 at 18:45
  • 2
    @ashley you can also take a look at this post similar to your query , but do post some code for us to help http://stackoverflow.com/questions/36919399/angular-2-view-not-updating-after-model-changes – Rahul Singh Mar 30 '17 at 18:48
  • 1
    See http://stackoverflow.com/questions/34456430/ngfor-doesnt-update-data-with-pipe-in-angular2 and http://stackoverflow.com/questions/39757603/unraveling-angular-2-book-chapter-1-example-5/39761822#39761822 – yurzui Mar 30 '17 at 18:54
  • Hello, Thanks for your reply. I have added the pure property to the pipe and set it to false and it works. But the thing is the pipe is being executed on every keystroke which I think is not that efficient. To add employee, I need to go on another page to add the details and then pressing save, it will return to this view where it displays the summary and the total. Is there not another way to detect that change when that view is showed instead of every keystroke? – ashley Mar 31 '17 at 02:07

0 Answers0