diff --git a/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee index 684109f7e4..b7bff59def 100644 --- a/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee @@ -80,3 +80,11 @@ Darkswarm.controller "ProductsCtrl", ($scope, $filter, $rootScope, Products, Ord $scope.query = "" $scope.taxonSelectors.clearAll() $scope.propertySelectors.clearAll() + + $scope.refreshStaleData = -> + # If the products template has already been loaded but the controller is being initialized + # again after the template has switched, refresh loaded data to avoid conflicts + if $scope.Products.products.length > 0 + $scope.Products.products = [] + $scope.update_filters() + $scope.loadProducts() diff --git a/app/views/shop/products/_form.html.haml b/app/views/shop/products/_form.html.haml index 7378ef2fea..5e45c44fa1 100644 --- a/app/views/shop/products/_form.html.haml +++ b/app/views/shop/products/_form.html.haml @@ -1,5 +1,5 @@ .footer-pad.small-12.columns - %products{"ng-controller" => "ProductsCtrl", "ng-show" => "order_cycle.order_cycle_id != null", "ng-cloak" => true } + %products{"ng-controller" => "ProductsCtrl", "ng-init" => "refreshStaleData()", "ng-show" => "order_cycle.order_cycle_id != null", "ng-cloak" => true } // TODO: Needs an ng-show to slide content down .row.animate-slide{ "ng-show" => "query || appliedPropertiesList() || appliedTaxonsList()" }