8

I have a component which displays a UI similar to a spreadsheet. There are lots of elements with two way binding [(ngModel)] to a mutable Object.

As soon as the number of inputs grows past 100 or so inputs the UI becomes sluggish. The profiler shows a lot of time in Decimal format (decimal pipe).

I can think of a couple of possible solutions:

  1. Using immutable objects somehow?
  2. Customising the 2 way databinding?

I am not using ChangeDetectionStrategy OnPush, but I am curious as to how this will help and how to actually implement it with [(ngModel)] on html inputs.

7
  • Are you using changeDetection: ChangeDetectionStrategy.OnPush? Commented Dec 12, 2016 at 21:53
  • No, I am not using ChangeDetectionStrategy OnPush Commented Dec 12, 2016 at 22:03
  • 1
    That's the first measure for better performance for mor fine-grained control aboit how much work change detection should do. Commented Dec 12, 2016 at 22:06
  • Try to use OnPush for your ChangeDetectionStrategy as @GünterZöchbauer said and you could try to do a virtual-scroll to avoid the need of more inputs. Commented Dec 14, 2016 at 23:36
  • 1
    Why not to use FormGroup? Commented Dec 14, 2016 at 23:39

2 Answers 2

5
+25

Many input fields on a page is stressful both for the CPU and the user.

Instead of showing a spreadsheet with many input fields simultaneously - I would rather make the cell an input field only when focused, and otherwise only show the value of the cell. Use *ngIf on the input checking for the current cell being edited.

This way you should be able to keep the functionality you want, but by making only the focused spreadsheet cell an input - that should improve the performance of the page.

Sign up to request clarification or add additional context in comments.

Comments

1

Since NgModel is directive it does not support change detection strategies, it means that you should avoid NgModel. The only way is to create custom component that uses OnPush strategy and wraps input field.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.