Angular version: 1.6.0
I have a problem in understanding why I notice different behaviours in notifing to the view a change in a boolean property.
This is the view:
<div ng-app="testApp">
<div ng-controller="testController as viewModel">
<h1>
"IsLoading" value: {{ viewModel.isLoading }}
</h1>
<h1>
"IsLoadingV2" value: {{ viewModel.isLoadingV2 }}
</h1>
</div>
</div>
This is the controller:
(function() {
angular.module('testApp', [])
.controller("testController", testController);
function testController($interval) {
viewModel = this;
viewModel.isLoading = true;
viewModel.isLoadingV2 = true;
viewModel.refreshView = function () {
viewModel.isLoading = !viewModel.isLoading;
viewModel.DoNothing();
viewModel.isLoading = !!viewModel.isLoading;
viewModel.isLoadingV2 = true;
viewModel.DoNothing();
viewModel.isLoadingV2 = false;
};
viewModel.DoNothing = function() {
//
}
var invertPropertyTimer = $interval(function () {
viewModel.refreshView();
}.bind(this), 1000);
}
})();
If you run the code above, you will notice that:
viewModel.isLoading = !viewModel.isLoading;updates correctly the property, and correctly reflects its change to the view- Setting directly
trueandfalsedoesn't work.
What's the reason?
You can find the full working example on Plunker (last version): https://plnkr.co/edit/HiOQDVBQ7Wztmj5Dr8zb?p=preview