How to favorite items from a list


#1

Hey all. Im kinda new to ionic but i chose to learn on the go by diving into creating my first app. All was well until i got stuck at creating a favorites page.

I basically want to add items to a favorites page when a favorite button is clicked on an item from a list populated by a local json file in another page.

Here’s my html

<ion-list can-swipe="true">
      <ion-item ng-repeat="institution in institutions | filter:school | filter:query" href="#/app/playlists/{{institutions.indexOf(institution)}}"  >
      <img class="itemizer" ng-src="{{institution.avatar}}">
      <div class="abbrItem">{{institution.abbr}}</div>
       <p>{{institution.name | uppercase}}</p>
       
        <div class="locationItem">{{institution.location}}</div>
        <ion-option-button class="ion-ios-star" ng-click="addFavorite(institution)">
        </ion-option-button>
      </ion-item>
  </ion-list>

here’s my controller

.controller('HomeCtrl', ['$scope', '$http', '$ionicScrollDelegate','$stateParams',
  function($scope, $http, $ionicScrollDelegate,$stateParams)
  {
    var urlJson = "json/institution.json";
      
      $http.get(urlJson).success 
      (function(data){
        $scope.institutions= data;

      });
      $scope.scrollTop = function() {
        $ionicScrollDelegate.scrollTop(true);
      };
             

    }]
)

i honestly dont know how to go about my addFavorite() function…
I have read about local storage and ng-storage but i cant wrap my head around the logic of it all.
im a graphic designer first and an aspiring programmer second. Any help i can get with be greatly appreciated.


#2

You may find this interesting, some time ago I wrote an article describing Master-Detail pattern in Ionic Framework. I think it should be useful to you. You will also find a working example to play with.

###Read it here.