javascript - angular how to reload a controller -


i have categoriespanel controller on ng-click want show products belongings category inside ng-controller productspanel. problem im having every time click on ng-click="selectorcategory" products in clicked category after refresh page.

     <div class="col-md-6 m-t-10" ng-controller="productspanel" style="padding-right:1px;">         <div class="panel panel-default" style="height: 700px">             <div class="panel-body">                 <div ng-repeat="product in products" class="productrow">                     <a href="javascript:;" class="btn btn-white btn-xlarge btn-block">{{product.product}}</a>                 </div>             </div>         </div>     </div>      <div class="col-md-3 m-t-10" ng-controller="categoriespanel" style="padding-left: 0; padding-right: 5px">         <div class="panel panel-default" style="height: 700px">             <div class="panel-body">                 <div ng-repeat="category in categories" class="categoryrow">                     <a href="javascript:;" data-id="{{category.categoryid}}" ng-click="selectedcategory($event)" class="btn btn-white btn-xlarge btn-block">{{category.category}}</a>                 </div>             </div>         </div>     </div> 

this angular script getting right data backend data shows in producspanel controller when refresh page. want data show ng-click.

app.controller('categoriespanel', function($scope, $location, $http, $localstorage){  var companyid = $localstorage.employee[0].companyid;  $http({     method  : 'get',     url     : 'http://localhost:8888/categories/ajax_getcompaniescategories',     params: {companyid: companyid} }) .success(function(data){     $scope.categories = data;     $localstorage.categories =  data; });  $scope.selectedcategory = function(event){      $localstorage.categoryid = $(event.target).data('id');      $http({         method  : 'get',         url     : 'http://localhost:8888/products/ajax_getcategoryproducts',         params: {categoryid: $localstorage.categoryid}     })     .success(function(data){         $scope.products = data;         $localstorage.products =  data;      }); }  });  app.controller('productspanel', function($scope, $location, $http, $localstorage){ $scope.products = $localstorage.products; });  /* end controllers */ 

maybe product array pointing gets clear when call getcategoryproducts made. can fix callback ajax_getcategoryproducts , change success push elements array instead of reassignment.

.success(function(data){         $scope.products.length=0;         data.foreach(function(p) {             $scope.products.push(p);         });         $localstorage.products =  $scope.products;      }); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -