title: Angular 6: saving data to local storage
body: <p>I have a data table which display data from external API, I want the number of items /element  on the table page should be saved in local storage</p>
  
  <p>Here is what I have tried so far: </p>
  
  <pre><code> ngOnInit() {
    this.moviesService.getPopularTVShows().subscribe(res =&gt; {
      this.dataSource = new MatTableDataSource(res.results);
      this.dataSource.paginator = this.paginator;
      this.dataSource.sort = this.sort;
      localStorage.setItem(this.dataSource, this.dataSource.length);
      console.log(localStorage.length);
    });
  }
  </code></pre>
  
  <p>When I run my app, the console displays <code>undefined</code></p>
  
  <p>What is wrong with my code? any help or suggestion is welcomed, newbie trying new stuff.</p>