AjRev
AjRev

Reputation: 95

HTML div not being updated

Not an angular expert. I'm developing a python-flask application with angularjs in the front end. I make a http call to python that returns an object. I then check if the value of a key is 'dev' or 'prd' and then use ng-show to display the corresponding divs. My problem is that the div does not update correctly every time I click on the button to retrieve the data from python.

angular.forEach(response.data,function (value,key) {
    if (value == 'dev') {
    $scope.showval="True";
    //$scope.showprd="False";

    } else if (value == 'prd') {

       $scope.showprd="True";
        //$scope.showval="False";
    }
});

I tried $scope.$apply(), $timeout() and also tried to set the ng-show variable to false but none worked. $scope.$apply gave me an error that the digest cycle is in progress. So,i think the divs are being processed by angular. Need help to determine what's wrong. Thanks for your time.

Upvotes: 0

Views: 46

Answers (1)

Sudhir Ojha
Sudhir Ojha

Reputation: 3305

You could set you showval and showprd as false initially and in a certain condition your can assign it as true like following:

angular.forEach(response.data, function(value, key) {
    if (value == 'dev') {
        $scope.showval = true;
        $scope.showprd = false;

    } else if (value == 'prd') {
        $scope.showprd = true;
        $scope.showval = false;
    }
});

And i am supposing your html like

<div ng-show="showval && !showprd">Dev</div>
<div ng-show="!showval && showprd">Prod</div>

Upvotes: 1

Related Questions