I use a smart table ( http://lorenzofox3.imtqy.com/smart-table-website/ ) for AngularJS, and I created a flag called isReset that will cause the table to reload. This is because I have a directive that monitors the flag, and the update will start when isReset is installed, and after it is updated, it will turn off the flag again.
My problem is that when I set the flag, it runs for the first time, but after observing the flagβs behavior it seems like it never returns to false. I tried to manually set the flag to false, but the next time around $ watch it didn't even work. My code is as follows, it would be great if you could help me shed some light on the problem. The strangest thing is, I have another place where I use it the same way, and it works as intended.
Js
$scope.resetFilter = function() { $scope.timestampFilter = ""; $scope.levelFilter = ""; }; $scope.getAPIServerLogs = function (tableState) { $scope.isLoading = true; ServerLog.get({ "serverType": "API", "timestampFilter": $scope.timestampFilter, "levelFilter": $scope.levelFilter, "offset": tableState.pagination.start, "limit": tableState.pagination.number, "sortField": tableState.sort.predicate, "order": tableState.sort.reverse ? "desc" : "asc" }, function (response) { $scope.isLoading = false; $scope.serverlogs = response.data; $scope.displayedserverlog = [].concat($scope.serverlogs); tableState.pagination.numberOfPages = response.pages; }); };
Directive
directives.directive('stReset', function () { return { require: '^stTable', replace: false, scope: {stReset: "=stReset"}, link: function (scope, element, attr, ctrl) { scope.$watch("stReset", function () { if (scope.stReset) {
HTML
<table st-table="displayedserverlog" st-safe-src="serverlogs" st-pipe="getAPIServerLogs" class="table table-striped table-hover logtable"> <thead st-reset="isReset"> <tr> <th st-sort-default="reverse" st-sort="timestamp" width="11%">Timestamp</th> <th st-sort="logger" width="30%">logger</th> <th st-sort="level" width="3%">Level</th> <th st-sort="thread" width="11%">Thread</th> <th st-sort="message" width="45%">Message</th> </tr> </thead> <tbody ng-repeat="serverlog in serverlogs"> <tr ng-click="click(serverlog)" ng-class="{'tr-active':serverlog.isClicked, 'pointer danger':serverlog.exception}"> <td>{{serverlog.timestamp | date: 'yyyy-MMM-dd hh:mm:ss'}}</td> <td>{{serverlog.logger}}</td> <td>{{serverlog.level}}</td> <td>{{serverlog.thread}}</td> <td>{{serverlog.message}}</td> </tr> <tr ng-show="serverlog.isClicked"> <td colspan="6"> <div class="row"> <div class="col-md-12"> <div>{{serverlog.exception}}</div> <pre><div ng-repeat="trace in serverlog.stacktrace track by $index" class="stacktrace">{{trace}} </div></pre> </div> </div> </td> </tr> </tbody> <tfoot ng-hide="isLoading"> <tr> <td colspan="10" class="text-center"> <div st-pagination="" st-items-by-page="50"></div> </td> </tr> </tfoot>