Angle variable scope not updating

Asked

Viewed 118 times

1

I have a bizarre problem with a variable that I created in HTML with Angularjs. I even tried to instantiate it in Controller to see if that was the problem but no.

I have a button that on ng-click i say that this variable (which has not yet been instantiated) becomes the opposite of it. To the button it works. It comes null first, but by clicking the button a few times it gains value and becomes True or False (according to the click). I display this variable inside the button and it works. Now if I try to use it elsewhere, it doesn’t work.

<button type="button" ng-click="nova_variavel_criada = !nova_variavel_criada;">{$nova_variavel_criada$} . {$nova_variavel_criada ? 'PRIMEIRO CASO':'SEGUNDO CASO'$}</button>
AQUI ELA NÃO PRINTA NENHUM RESULTADO: {$nova_variavel_criada$}

About the {$ $} is because I use Django and had to change the keys.

Inside the button, when clicking, the phrase changes normally. Even the print behind appears "TRUE" and "FALSE" according to Click. The problem is outside the button, nothing appears.

1 answer

0


I honestly did not understand what happened. My solution was to call a function and inside make the change. This way the scope variable changes in every template.

HTML

<button type="button" ng-click="change_variavel()">{$nova_variavel_criada$}</button>
{$nova_variavel_criada$}

Angular

$scope.change_variavel = function() {
    $scope.nova_variavel_criada = !$scope.nova_variavel_criada;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.