Fix angular templates bug

Angular controller data was being partially preserved when switching back and forth between tab templates, causing the ProductsCtrl to hold duplicate datasets when it is re-initialized after going from the shop tab to another tab, then back again.
This commit is contained in:
Matt-Yorkley
2020-01-08 16:14:29 +01:00
parent 43eef0c8c6
commit d508e7772c
2 changed files with 9 additions and 1 deletions

View File

@@ -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()

View File

@@ -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()" }