角度变化和全负载事件

时间:2022-10-27 23:51:50

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).

我需要在一个完全加载的页面(比如window.onload)之后调用一个函数,但是如果我改变视图,这个事件不会触发。我尝试在我的控制器中调用函数(当视图更改时触发),但函数只工作了一半(在ng-model在输入文件中写入值之后,我的函数需要在DOM中做一些更改)。

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'...

我想知道我是否可以做一个条件,比如“在ng-model完成工作后再调用那个函数”……

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 !

谢谢大家的帮助!

1 个解决方案

#1


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.

所以,如果你需要在加载所有东西之后调用一些东西,这是给你的。基本上,您也可以使用它来触发多个transcludes发生后的首字母事件。

#1


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.

所以,如果你需要在加载所有东西之后调用一些东西,这是给你的。基本上,您也可以使用它来触发多个transcludes发生后的首字母事件。