Update side menu with JSON data


I have a homePage with a simple Username field and “login” button, after a valid username is filled and login button clicked,
3 functions triggers on login
a) I generate the user related JSON data,this JSON also contains the products the user has subscribed for.
b) Each product becomes a menu item.
c) Then the side-menu slides from left side containing updated menu items

I was fortunate enough to get all three working except one ,
The menu which slides soon after I click the login shows me the old menu items, So need to refresh the page to check my updated menu,

// productList Injected to the controller is a service which returns my products array  
.controller('MenuCtrl', function($scope,productList) {

  var prodList = productList.getProducts();
  //Initial values are false that the products will be disabled
  //Loop through the Productlist array returned by service function
  //Turns "true" if product is availabile for the user

  for(var x=0;x<prodList.length;x++){


  //Finally the menu updates with ng-if directive checking if the return value is true/false


<ion-list ng-controller="MenuCtrl"> 
        <ion-item ng-if="Shoe" nav-clear menu-close href="#/app/shoe">     Shoe    </ion-item>
        <ion-item ng-if="Shirt" nav-clear menu-close href="#/app/shirt">    Shirt  </ion-item>
        <ion-item ng-if="Hat" nav-clear menu-close href="#/app/hat">     Hat  </ion-item>

How am I supposed to see my updated menu without refreshing the page ?

Thank you.


First … Adding a separate scope for each product seems excessive. Why not use an array instead:

var prodDefaults = {
    shoe: false,
    shirt: false,
    hat: false

$scope.product = _.assign(prodDefaults, prodList)

Now if you get the prodList formated in the same way, you can just use lodash assign() method to override the default values as shown above, and then do the following in the view:

    <li ng-if="product.shoe"><a ui-sref="shoepage">Shoes</a></li>
    <li ng-if="product.shirt"><a ui-sref="shirtpage">Shirts</a></li>
    <li ng-if="product.hat"><a ui-sref="hatpage">Hat</a></li>