herrh herrh - 6 months ago 55
HTML Question

Show element after pageload with ng-show and $window.onload

I have a mainController which looks like below. I want to display a div after the completed pageload with ng-show. My

$scope.windowLoaded
is true after pageload, but the div with ng-show doesn't appear.

angular.module('myApp')
.controller('mainController', function ($scope, $window) {

$scope.windowLoaded = false;
console.log('loading completed: ' + $scope.windowLoaded);
$window.onload = function() {
$scope.windowLoaded = true;
console.log('loading completed: ' + $scope.windowLoaded);
};

});


html:

<div ng-show="windowLoaded == true">
Show this div after pageload succeeded.
</div>

Answer

you can try with

$scope.$apply(function () {
 $scope.windowLoaded = true;
});
Comments