简体   繁体   English

如何显示保存在本地存储中的模板? (角材料)

[英]How can I display template who is saved in localstorage? (Angular Material)

I have problem with displaying templates in Angular Material.我在 Angular 材料中显示模板时遇到问题。 I want to save to localstorage my template who I choose in menu, but my app display another template (dafault template) after refresh page.我想将我在菜单中选择的模板保存到本地存储,但我的应用在刷新页面后显示另一个模板(默认模板)。 How can I save template to localstorage in this example?在此示例中,如何将模板保存到本地存储?

Source app: https://stackblitz.com/edit/angular-event-emitting-to-change-theme-localstorage?file=src/app/app.component.ts源应用程序: https://stackblitz.com/edit/angular-event-emitting-to-change-theme-localstorage?file=src/app/app.component.ts

Do you know how resolve this thing?你知道怎么解决这个问题吗? Thank you very much!非常感谢!

I don't see you loading the theme anywhere.我没有看到您在任何地方加载主题。

I would do it in ngOnInit for navbar.component.ts :我会在ngOnInit中为navbar.component.ts执行此操作:

ngOnInit() {
  const selectedTheme = localStorage.getItem('themes');
  if (selectedTheme) {
    this.selectedTheme.emit(selectedTheme);
  }
}

Here's an updated demo: https://stackblitz.com/edit/angular-event-emitting-to-change-theme-localstorage-9l9gqa?file=src/app/navbar/navbar.component.ts这是一个更新的演示: https://stackblitz.com/edit/angular-event-emitting-to-change-theme-localstorage-9l9gqa?file=src/app/navbar/navbar.component.ts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM