angularjs - Empty an array before push -
i took project using angularjs. there filtering system. actually, click on category add category list. industries got category shown. note click on selected category remove category.
i click replace filtering category each click not add category. how should modify code:
$scope.changercategorie = function(category , name ){ if( jquery.inarray(category, $scope.selected ) !== -1) { angular.foreach($scope.selected , function(obj,index){ if( category == obj ){ $scope.selected.splice(index,1); $scope.selected_name.splice(index,1); } }); }else{ $scope.selected.push(category); $scope.selected_name.push(name); } $scope.selected_filter = $scope.selected.join(', '); }
i tried doesn't work
$scope.changercategorie = function(category , name ){ $scope.selected = 0; $scope.selected_name = 0; $scope.selected = category; $scope.selected_name = name; $scope.selected_filter = $scope.selected.join(', '); }
and get
$scope.selected.join not function
if remove line related selected.join got error after 2 clicks:
duplicates in repeater not allowed. use 'track by' expression specify unique keys. repeater: tags in selected_name, duplicate key: string:l
how should do?
i believe preferred way empty array in javascript set length 0: $scope.selected.length = 0
.
the reason getting error on join() setting $scope.selected
directly category, not array. fix that: $scope.selected = [category];
of course, need 1 of these methods. either empty followed push, or direct assignment. if planning on getting rid of multiple filter feature, may better in long run store category rather array.
Comments
Post a Comment