javascript - AngularJS $scope issues in tabset -
i have problem trying watch in controller collection generated filter in view.
i store filtered data in variable :
 <table class="table">      <tr ng-repeat="item in filteredcollection = (mycollection | filter: txtsearch)">          <td ng-bind="item"></td>      </tr>  </table>   and subscribe changes of 'filteredcollection ' in controller :
$scope.$watchcollection('filteredcollection', function() {     if (typeof($scope.filteredcollection) != 'undefined')         console.log('results changed : ' + $scope.filteredcollection.length); });   i have set this jsfiddle show issue : watch function never called.
fun fact, works when remove <tabset> <tab> tags in html. think messed $scope, don't why. maybe tabset create new $scope child or something.
i hope guys find out going on here,
cheers
try put filteredcollection in object, change correct scope property:
$scope.obj = { filteredcollection : [] }; $scope.$watchcollection('obj.filteredcollection', function(newval) {     if (typeof($scope.obj.filteredcollection) != 'undefined')         console.log('results changed : ' + $scope.obj.filteredcollection.length); });   in html:
<tr ng-repeat="item in obj.filteredcollection = (mycollection | filter: txtsearch)">   see fiddle.
Comments
Post a Comment