Florian
Florian

Reputation: 197

execute directive function after ng-cloak

My content use ng-cloak directive and i would like to get a element height with innerHeight() in a directive.

But, when the innerHeight() is use the element is hide by ng-cloak so the result is always 0.

I tried

link: function postLink(scope, element, attrs) {}

Or

$timeout(function(){}

but same result.

Anyone know a function or event for this ?

Thanks.

Upvotes: 2

Views: 317

Answers (1)

Alex Alarcon
Alex Alarcon

Reputation: 51

This solution worked for me:

Add "data-ng-init" function call in a div inside your body with ng-cloak.

<body layout="row" ng-cloak>
  <div ng-controller="PageCtrl" data-ng-init="onloadFunction()">
    ...

In your app.controller, define this function and add your code in the "else" clause:

$scope.onloadFunction = function() {
  if (angular.element(document.body)[0].className == 'ng-cloak') {
    $timeout(function() {
      $scope.onloadFunction();
    },100);
  } else {
    // Here, page is displayed.
  }
}

Hope this helps.

Upvotes: 0

Related Questions