reload - The Binding Only Updates After Clicking the Element, Though the String in the Controller Has Already Been Updated (Angular 1.5) -


i have ng-class attribute (that didn't write on own). bound string variable in controller . looks like: <some-tag ng-class="'indicator_' + $ctrl.stringvalue"></some-tag>.

when window first load - contain correct data, after string updated in controller - value in class attribute updates after i'm clicking element (the click open list, don't think it's relevant).

i've read first thing check in these cases, code surrounded $scope.$apply. is, cause when try add - error saying "$digest in progress". looking $ctrl , ng-class info, read angularjs component doc , this site, gave me basic background these subjects.

the thing is, couldn't find examples of ng-class $ctrl. maybe it's irrelevant, maybe not :)

example irrelevant question found in subject is: angular ngclass not updating classes though condition change expected. in general, of examples found include curly brackets, don't think relevant in case, since i'm binding string (maybe i'm mistaking :) ).

i suspect didn't bind correctly, don't know why.


edit:

after continuing search subject, i'm no longer sure it's related ng-class (so edited title well). looks more refresh problem.

i'm puzzled why page doesn't refresh, since everywhere read - angular should call digest function on own, , should not interfere.

edit2:

i'm working typescript, , stringvalue updated via event service. string update - i'm not sure relevant information understand problem, worth mentioning :)

problem solved!! :d

all had do, add $timeout(0) after updating string in controller!

the explanation: digest problem, , reason couldn't use $scope.$apply(), because trying directly. needed safe apply, means - first make sure there's no digest on scope, , run apply.

turns out easy way it, use $timeout(0).


Comments