Persisting and accessing values globally in multiple components in Angular 2
问题 I have a settings page where users can save some config variables, such as a Username. The user can also change the username on that page. But when I go to another Component (page) and back, the username isn't saved. I also want to show the username in the other components. How do I do that? With a global variable? Structure: - App - app.ts (main) - setting.ts - someOtherComponent.ts 回答1: What you need is a service to maintain the state of your variables. You would then be able to inject that