Why is the variable available only in the template when passing onLoad to ng-include?

I am embarrassed about how the angular area works !!!

I pass two variables to one template using ng-init and onLoad. Both values ​​of the variable are available from the template, but there is one controller that I bound to this template. I think why both variables print their value from the template, but print undefined (onLoad varibale) when accessing the controller.

Fiddle illustrating my problem jsFiddle

I understand that when we pass a variable using ng-init, it creates this variable inside the current scope, but what onLoad is passed for this variable?

Please tell me how it works.

Thanks.

+4
source share
2 answers

Both variables are available for the second controller.

However, a (similar) second controller is created before the onload expression is expressed. If you want to access the scope variable, you can do it in hours (you probably want to use the clock, not the initial values ​​of the scope variables, anyway - what if your variable is the result of a promise?).

Here is an example showing that you can access the download from a second controller:

http://jsfiddle.net/rDP2t/3/

+3
source

Since ng-init is evaluated angular before the page is parsed by the browser. Thus, the controller receives the first value. After that, the download occurs. Therefore, setting the value to onload is too late.

+2
source

Source: https://habr.com/ru/post/1498942/


All Articles