Best Practice: "Master-Detail App"

Hi guys,

in my App i´m displaying data from about 2000 stores.

When the App gets opened, it shows the data summed up (For example total revenue, number of open stores, number of purchases, …). That part is already working nicely.

But then i´m displaying a list with every store. On selecting one of these items, the app should be showing only the data of this store.

My first idea was using the $rootScope. On the one hand, it didn’t work as i hoped, on the other hand i read, that using $rootScope is bad practice.

Currently i’m stuck. Would appreciate every hint and idea!

Greetings :slight_smile:

Use a factory.
Place this in your app.js

.factory('storeService', function() {
  var oStore = '';

  return {
    getStore: function () {
      return oStore;
    },
    setStore: function (oNewStore) {
      oStore= oNewStore;
    }
  };
});

And in your controller:

.controller(MasterCtrl, function($scope, storeService)
   storeService.setStore(oClickedStore);


.controller('DetailCtrl', function($scope, storeService)
    $scope.oStore = storeService.getStore();

Thank you @jiffer .

Clean and simple… And i can always check, if a store is already set.

I get the impression that for most questions the answer is: “use a factory” :smiley: