AngularJS scope variable not updating

1

I'm having a bizarre problem with a variable I created in HTML itself with AngularJS. I even tried to instantiate it on the Controller to see if that was the problem but no.

I have a button that in ng-click I say that this variable (which has not yet been instantiated) becomes the opposite of it. For the button works. It comes with null first, but clicking the button a few times it gains value and becomes True or False (depending on the click). I display this variable inside the button and it works. Now if I try to use it elsewhere, it does not 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 {$ $} is because I use Django and had to change the keys.

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

    
asked by anonymous 21.09.2017 / 20:15

1 answer

0

I honestly did not understand what happened. My solution was to call a function and there to make the change. This way the scope variable changes throughout the 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;
}
    
28.09.2017 / 22:15