我想在localStorage中存储一组对象.
这是我的代码片段,用于存储组件阶段的对象数组.
this._authenticationService.getProfilByLogin(this.form.value.j_username)
.subscribe(result => {
console.log('inside getting profils');
console.log(result.json().ecomServices);
localStorage.setItem('services_assigned', result.json().ecomServices);
}, error => {
Run Code Online (Sandbox Code Playgroud)
这是试图将其恢复到另一个组件中的代码.
import {Component, OnInit} from '@angular/core';
import {EcomService} from "../../model/EcomService";
@Component({
selector: 'app-sidebar-nav',
templateUrl: './sidebar-nav.component.html',
styleUrls: ['./sidebar-nav.component.css']
})
export class SidebarNavComponent implements OnInit {
public ecomServices: EcomService[] = [];
constructor() {
}
ngOnInit() {
this.ecomServices = localStorage.getItem('services_assigned');
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的模特课
export class EcomService {
public eseCode: number;
public eseLabel: string;
}
Run Code Online (Sandbox Code Playgroud)