[英]Get data from localstorage and display it in view using ngx-translate | Angular
I have a task have to display data from localstorage in html using ngx-translate.我有一个任务必须使用 ngx-translate 在 html 中显示来自本地存储的数据。 I have an backend spring-boot application with a controller that sends data downloaded from the database to the frontend.
我有一个后端 spring-boot 应用程序和一个 controller 将从数据库下载的数据发送到前端。 This data is stored in localstorage.
此数据存储在本地存储中。 They are literals.
它们是文字。 I have little in common with Angular.. I work in Java, but I need to do it:/ I am asking for your understanding.
我与 Angular 几乎没有共同之处。我在 Java 工作,但我需要这样做:/ 我请求您的理解。
localstorage:
key | value
--------------------------------------------------
Platform.Title | "Title"
Platform.Home | "Home"
Platform.Dashboard | "Dashboard"
Library.Title | "Library"
Library.Home | "Home"
Library.Dashboard | "Dashboard"
This what i need to do is: make service to get data from localstorage, i know i have to do it with我需要做的是:提供服务以从本地存储中获取数据,我知道我必须这样做
localstorage.get(key);
What I need to achieve is eq我需要实现的是 eq
<mat-card-title>{{'Platform.Title' | translate }}</mat-card-title>
and this should show value of "Platform.Title" - here "Title"这应该显示“Platform.Title”的值 - 这里是“Title”
I have keys which starts with different values Platform or Library.我有以不同值平台或库开头的键。 In platform.component.html i need to display all starts with "Platform" and in library.component.html all with "Library"
在platform.component.html中,我需要显示所有以“Platform”开头的内容,在library.component.html中,所有内容都以“Library”开头
My ideas so far have not worked, it does not even show because it is a shame.到目前为止,我的想法还没有奏效,它甚至没有表现出来,因为它是一种耻辱。 I have no idea how should servis in Angular looks like or some ngx-translate loader to achieve the planned effect.
我不知道 Angular 中的 servis 应该如何或一些 ngx-translate 加载程序来达到计划的效果。 Could someone please help me?
有人可以帮我吗? Show the way to a solution or maybe a sample solution.
显示解决方案或示例解决方案的方法。
you can get your data from local storage in this way您可以通过这种方式从本地存储中获取数据
in your component.ts在你的 component.ts
public title;
ngOnInit(){
this.title = localStorage.getItem('KEY');
}
in your HTML在你的 HTML
<mat-card-title>{{title | translate }}</mat-card-title>
in your app module add在您的应用模块中添加
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);}
in your app component add在您的应用组件中添加
constructor(private translate: TranslateService) {
translate.setDefaultLang('en');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.