onLoad 和 ng-init 在角度上的区别 [英] Difference between onLoad and ng-init in angular

查看:23
本文介绍了onLoad 和 ng-init 在角度上的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习角度.我不明白 onLoad 和 ng-init 在变量初始化方面有什么区别.它在哪个范围内创建这个变量.

I am learning angular. I don't understand what is difference between onLoad and ng-init for initialization of a variable. In which scope it creates this variable.

例如

<ng-include onLoad="selectedReq=reqSelected" src="'partials/abc.html'"></ng-include>

OR

<ng-include ng-init="selectedReq=reqSelected" src="partials/abc.html"></ng-include>

也请给我一些关于隔离范围的想法.

Please also give me some idea about isolated scope.

推荐答案

ng-init 是一个指令,可以放在 div's, span 的,无论如何,而 onload 是特定于 ng-include 指令的属性,它作为 ng-init 起作用.要了解我的意思,请尝试以下操作:

ng-init is a directive that can be placed inside div's, span's, whatever, whereas onload is an attribute specific to the ng-include directive that functions as an ng-init. To see what I mean try something like:

<span onload="a = 1">{{ a }}</span>
<span ng-init="b = 2">{{ b }}</span>

您会看到只有第二个出现.

You'll see that only the second one shows up.

独立作用域是一个不典型地从其父作用域继承的作用域.用外行的话来说,如果你有一个不需要任意读写父作用域的小部件,那么你可以在小部件上使用一个隔离作用域,这样小部件和小部件容器就可以自由地使用它们的作用域而不会覆盖彼此的属性.

An isolated scope is a scope which does not prototypically inherit from its parent scope. In laymen's terms if you have a widget that doesn't need to read and write to the parent scope arbitrarily then you use an isolate scope on the widget so that the widget and widget container can freely use their scopes without overriding each other's properties.

这篇关于onLoad 和 ng-init 在角度上的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆