Faiz99 Faiz99 - 3 months ago 7
AngularJS Question

Angularjs -- refresh single column in view after update

I am printing records in view with ng-repeat.

There is a column named status, which is either 0 or 1.

<button class="btn btn-warning" ng-click="quizStatus(quiz)" ng-if="quiz.status == 0">Publish</button>
<button class="btn btn-warning" ng-click="quizStatus(quiz)" ng-if="quiz.status == 1">Drop</button>


Depending on the status, if i click the button it will invert status. My controller is sending me 0 or 1 after update.

app.controller('quizController', function($scope, $http,$sce){

$scope.quizStatus = function(quiz) {
var data = JSON.stringify({id : quiz.id });
$http.post('./quizStatus', data ).success(function(data) {
// data = 0 / 1;
alert("Status Changed");
});
};

});


I don't want to refresh the whole table as i only need to reflect the status change.

How do i accomplish this?

Answer

Just update the status of the quiz when you get the data back:

$scope.quizStatus = function(quiz) {
var data = JSON.stringify({id : quiz.id });
 $http.post('./quizStatus', data ).success(function(data) {
      // data = 0 / 1;
      alert("Status Changed");
      quiz.status = data;
   });
};