title: AngularJS localstorage for a factory
body: <p>I am a newbie to IonicFrameWork and was following their "starter tab" template and made a few modifications to "delete" and "bookmark" items from a factory. </p>
  
  <p>My <code>books.js</code> which contains the factory looks as follow: </p>
  
  <pre><code>.factory('Books', function() {
  
    // books data
    var books = [{
      id: 0,
      title: 'Sample Title',
      author: 'Sample Author',
      category: 'Horor, Fiction',
      cover: '/cover.jpeg',
      details: 'some details about the book',
      chapters: [
        {
          id : 1,
          name: 'Chapter 1',
          filename: 'chapter1.html',
        },
        {
          id : 2,
          name: 'Chapter 2',
          filename: 'Chapter2.html',
        }
      ]
    }
    .....  
    return {
      all: function() {
        return books;
      },
      // remove a book from the list
      remove: function(book) {
        books.splice(books.indexOf(book), 1);
      },
  </code></pre>
  
  <p>and my <code>controllers.js</code> looks like this: </p>
  
  <pre><code>....
  .controller('DashCtrl', function($scope, Books) {
  
    $scope.books = Books.all();
    $scope.remove = function(book) {
      Books.remove(book);
    };
  })
  .controller('singlebookCtrl', function($scope, $stateParams, Books){
    $scope.book = Books.get($stateParams.bookId);
    $scope.toggleIcon = function ($evemt, iconName, book){
    var buttonClasses = $event.currentTarget.className;
    // add the book to favorite
    if (....){
        book.isFavorite = true;
    }
    // remove the book from favorite 
    else {
        book.isFavorite = false;
    }
    ....
  </code></pre>
  
  <p>when I exit the app and open it again, the deleted item is back and favorite items are gone. </p>
  
  <p>When searching for a solution , I came across <a href="http://learn.ionicframework.com/formulas/localstorage/" rel="nofollow">this article</a> which states I should use <code>window.localstorage</code>. But not sure how I should apply this method for a factory. </p>