How can I change the value of a variable in AngularJs?

1

I need to create a variable that stores the state of the función I execute in the $ interval called $scope.getSignatureCallStatus(); that function executes a request that saves in a variable $scope.callStatus = res.data; the state ...
are 3 states :

{
    success
    fail
    hangup
}


So if the variable $scope.callStatus = 'success' keeps that value in a new variable or that it is TRUE , something like $scope.callStatusSucces = $scope.callStatus == 'success' , but since it is in an interval the value changes dynamically, then I want the new variable does not change the value ...

$scope.promise = $interval(function() {
    $scope.getSignatureCallStatus();
    $scope.showStatus = true;
}, 2500);


This is the function $scope.getSignatureCallStatus();

$scope.getSignatureCallStatus = function() {
        $http.get('url', {
            params: {
                param: param
            }
        }).then(function(res){
            $scope.callStatus = res.data;
        });
    };
    
asked by zerokira 08.03.2018 в 15:41
source

1 answer

2

By your question I understand that you only want to know when $scope.callStatus has been 'success' ever. In this case you can do the same thing that you asked in the question: declare a variable $scope.callStatusSucces (name proposed by you in the question) and assign it true when $scope.callStatus == 'success' .

The function would be like this:

$scope.getSignatureCallStatus = function() {
    $http.get('url', {
        params: {
            param: param
        }
    }).then(function(res){
        $scope.callStatus = res.data;
        if (!$scope.callStatusSucces) { // si '$scope.callStatusSucces' no ha sido setteado o '$scope.callStatus' nunca ha sido 'success'
            $scope.callStatusSucces = $scope.callStatus == 'success'
        }
    });
};
    
answered by 08.03.2018 / 17:34
source