1

If I have a list of checkboxes on Component 1 and I check the first checkbox. How do I retain the checked items when I navigate to other components?

Example:

1.) Navigate to Component 1 and check a checkbox for Item 1.

2.) Then I click a button which routes me to Component 2.

3.) Now I click another a button which routes me back to Component 1.```

Result: I want Item 1 to be checked.

How would I achieve that?

2

1 Answer 1

2

Return true from routerCanReuse() https://angular.io/docs/ts/latest/api/router/CanReuse-interface.html then the same component instance will be reuse instead of creating a new one.

Alternatively (as mentioned by micronyks) you can register a service in a common parent (might be the root component or bootstrap() for application wide sharing) and store and retrieve the values from there.

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

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.