Why is this simple AngularJS ng-show not working?
You need to tell angular that you updated the var:
function TestCtrl($scope) { $scope.loading = true; setTimeout(function () { $scope.$apply(function(){ $scope.loading = false; }); }, 1000);}
or just
function TestCtrl($scope, $timeout) { $scope.loading = true; $timeout(function () { $scope.loading = false; }, 1000);}
A nicer way of doing this is by calling $scope.$digest();
to update your UI
You need to use $timeout
and inject it in your controller:
function TestCtrl($scope, $timeout) { $scope.loading = true; $timeout(function () { $scope.loading = false; }, 1000);}
Edit:removed $scope.apply();
as @Salman suggested