0

I need to call a function after a fully loaded page (like window.onload) but this event is not trigger if I change the view.
I tried to call the function in my controller (which is trigger when the view change) but the function work only at half (my function need to make some change in the DOM after that the ng-model wrote values in the input fileds).

I would like to know if I can make a condition like 'call me that function after that the ng-model had done his job'...

Exemple :

// Case 1 //

// It works perfectly but not on viewChange.
window.onload = function() {
  // My stuff...
}

// Case 2 //

function onLoadView() {
  // My stuff...
}
// In my controller it is always call but sooner than expected
onLoadView();

// Case 3 //

function onLoadView() {
  window.onload = function() {
    // My stuff...
  }
}
// In my controller, the window.onload is not trigger
onLoadView();

Thanks for the help folks !

C0ZEN
  • 894
  • 11
  • 41
  • Uh, typically you should not manipulate the DOM yourself but use Angular templating to change it. – Johannes Jander Jan 25 '16 at 12:15
  • Maybe I used bad words but I only want to manipulate DOM class. Exemple : if this input is empty add class empty... However it doesn't work because the ng-model do his job after the call of my function... – C0ZEN Jan 25 '16 at 12:17
  • Use `ng-class` for that: `input ng-class="{ 'empty': !my-input" ng-model="my-input">` – Johannes Jander Jan 25 '16 at 12:23
  • Bad news. I used a composant (datepicker) and I need to modify the DOM (I can't use a directive because the composant is build by js script). Then the initial problem still need to be solved. – C0ZEN Jan 25 '16 at 13:53
  • There just is no callback for what you want to do. You could use `$scope.$watch()` to be informed if the input changes, but apart from that, you are out of luck. – Johannes Jander Jan 25 '16 at 13:55

1 Answers1

0

Solution:

I read this topic which is exactly what I needed. I tried the directive and it worked as expected.

So, if you need to call something after everything is loaded, this is for you.
Basically, you can use it as well to trigger initials events after multiples transcludes had occured.

Community
  • 1
  • 1
C0ZEN
  • 894
  • 11
  • 41