Why variable is accessible only in template when passed by onLoad in ng-include?

angularjs

Solution

Both variables are accessible to the second controller.

However (it looks like) the second controller is created before the `onload` expression is evaluated. That being said if you'd like to access the scope variable you can do so through a watch (you probably want to be using watches rather than using the initial values of scope variables, anyway - what if your variable is the result of a promise?).

Here is an example that shows you can access the load from the second controller:

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

Problem

I am confuse about how angular scope works!!! I am passing two variable to one template using ng-init and onLoad. Both variable value accessed from template but there is one controller which I have bound to that template. I am thinking why both variable prints its value from template but prints undefined (onLoad varibale) while accessing from controller. `Fiddle illustrating my problem` jsFiddle What I understand is, when we pass variable using ng-init, it creates that variable inside current scope but what for that variable which is passed by onLoad?? Please tell me how it exactly works. Thank you.

Original source