title: Angular 2 - Storing and Getting Objects array from localStorage
body: <p>I'd like to store an array of objects in <strong>localStorage</strong>.</p>
  
  <p>This is snippet of my code storing the array of objects at component stage.</p>
  
  
  
  <pre class="lang-ts prettyprint-override"><code>this._authenticationService.getProfilByLogin(this.form.value.j_username)
    .subscribe(result =&gt; {
       console.log('inside getting profils');
       console.log(result.json().ecomServices);
       localStorage.setItem('services_assigned', result.json().ecomServices);
    }, error =&gt; {
  </code></pre>
  
  <p>This is the code trying to get it back in another component.</p>
  
  <pre class="lang-ts prettyprint-override"><code>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');
      }
    }
  </code></pre>
  
  <p>This is my <strong>model</strong> class</p>
  
  <pre class="lang-ts prettyprint-override"><code>export class EcomService {
  
    public eseCode: number;
    public eseLabel: string;
  
  }
  </code></pre>