angularjs - Output is concatenated -


new click on [filter] not clear previous output adding exists. example, if filtered "banned" see banned users list, next filter "registered" not remove "banned" adding "registered" end of table. in controller $scope.site_users overwritten, somewhere still saves previous filter output. why happens? may on packages side?

installed packages:

urigo:angular - angular angularui:angular-ui-router accounts-password accounts-ui twbs:bootstrap 

removed packages:

insecure autopublish 

or in code

controller:

angular.module("sis_admin_am").controller("userslistctrl", ['$scope', '$meteor',     function($scope, $meteor){          $scope.filter = function(){             $scope.site_users = '';             $scope.site_users = $meteor.collection(users).subscribe('site_users_filtered', {status: $scope.userstatus});         };     } ]); 

view:

<form ng-submit="filter()">     <button>filter</button>     <select ng-model="userstatus" >         <option ng-selected="selected">banned</option>         <option>registered</option>         <option>active</option>     </select> </form> <p></p> <table class="table">     <tr class="panel panel-default">         <th>name</th>         <th>email</th>     </tr>      <tr ng-repeat="user in site_users">         <td>{{ user.username }}</td>         <td>{{ user.email }}</td>     </tr> </table> 

server part:

meteor.publish('site_users_filtered', function(options) {     console.log('options:', options);     return users.find(options); }); 

that's because how subscriptions in meteor works. if add or change subscription without closing ones before, add them (which have aware of it). if want filter subscriptions (for security reasons) should change code that:

angular.module("sis_admin_am").controller("userslistctrl", ['$scope', '$meteor',     function($scope, $meteor){          var savedsubscriptionhandle = null;         $scope.filter = function(){             savedsubscriptionhandle.stop();             $scope.site_users = '';             $scope.site_users = $meteor.collection(users);             $scope.$meteorsubscribe('site_users_filtered', {status: $scope.userstatus}).then(function(handle){                 savedsubscriptionhandle = handle;             });         };     } ]); 

but if don't mind keeping data in local cache might easier use angular's filters or meteor's cursor syntax filter display.

more detailed explanation here: http://angular-meteor.com/tutorial/step_12


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -