NetGain | A high performance websocket server library powering Stack | Websocket library
kandi X-RAY | NetGain Summary
kandi X-RAY | NetGain Summary
A high performance websocket server library powering Stack Overflow.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of NetGain
NetGain Key Features
NetGain Examples and Code Snippets
Community Discussions
Trending Discussions on NetGain
QUESTION
I was getting bad performance on an Angular Material table. When I checked the console I could see it was binding each row multiple times although I can't see what's triggering it. I have reduced my code as simple as I can and I am still seeing the issue.
There are 257 rows, but the count in being logged to the console counts to 1542, which means each row seems to be being bound 6 times. The formatting function decimalTimeToHours should be called once for each row. Any ideas why it's binding so many times?
...ANSWER
Answered 2021-Apr-01 at 07:10The reason your decimalTimeToHours
method is getting called so many times relates to how Angular change detection works. Angular keeps track of any bindings in the HTML template, and updates the browser dom when the underlying value changes. But, this isn't a magical process. In order to know when an underlying value changes, Angular has to manually keep checking if these values have changed. It takes the current value and compares it against the last value it saw for that binding. If the value changes, it updates the dom. The finer details of how and when this detection process runs is a huge topic. The important part, though, is that when change detection runs (which appears to be happening 6 times) it goes to your binding to get the current value.
The problem stems from your use of a function there right in the template. Each time change detection wants to evaluate the value, it has to call that function in order to determine the value (which creates a new string each time), and then compares that against the old string. Not a huge problem, but it's something you could easily be avoiding. One solution would be to use an angular pipe to format the data the way you want to see it in the table:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install NetGain
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page