I am a newbie in angular, and I haven't been able to find any solid answers for this question... even though the answer might have been in front of me, I just couldn't see it.
I have this piece of html:
<ul class="wrapper" ng-controller="MyController as vks">
<li ng-repeat="myvar in vks.vk" class="padding-left" data-myvar-id="{{myvar.id}}">
<img src="images/someimage.svg" ng-show="{{myvar.id}} == {{myvar.chosen}}" class="some-class">
<a class="hvr-underline-reveal">{{myvar.name}}</a>
</li>
</ul>
And this is my controller:
app.controller('MyController', function() {
var i = 0;
var tmp = [];
for (var key in someObject) {
if (someObject.hasOwnProperty(key)) {
var obj = someObject[key];
if (obj.checked) {
tmp[i] = {name: obj.name, id: obj.id, chosen: someStaticVar};
i++;
}
}
}
this.vk = tmp;
});
I want to focus on this part which works the first time the page is loaded:
<img ng-show="{{myvar.id}} == {{myvar.chosen}}">
What happens when suddenly {{myvar.chosen}} (which is is set from a static global var) changes from some outside javascript? The HTML part is not refreshed, and that specific is still shown, but it should be another one shown. How can I reload only this controller? (or do something else to make this work as intended?)
Hope this makes sense...
<img ng-show="myvar.id == myvar.chosen">Also chosen is going to be set only when the controller is loaded the first time, so if someStaticVar changes, you could either compare with it directly in your html or have add a watch to it