本文介绍了AngularJS表达式中的$ locals是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AngularJS开发人员表达式指南提到了一个名为$locals的东西:

AngularJS Developer Guide on Expressions mentions something named $locals:

我不知道什么是本地对象",也无法在文档中找到有关$ locals的更多信息.目的是什么?您如何操作呢?

I don't understand what "locals object" is and I can't find any more info on $locals in docs. What is it's purpose? How do you operate on it?

推荐答案

在其中找到有关其更多信息的相关提交是,它也链接到要求引入$ locals的问题.

The relevant commit where to find more information about it is this one, which also links to the issue asking to introduce $locals.

简而言之,当使用'&'将参数传递给指令时,为了使指令能够在需要时执行某些代码(例如,当您使用ng-click="doSomething()"时),指令可以将信息传递给使用本地值的呼叫者.

In short, when passing a parameter to a directive using '&', in order for the directive to be able to execute some code when needed (for example when you use ng-click="doSomething()"), the directive can pass information to the caller using local values.

例如,您可以使用ng-click="doSomething($event)",其中$ event不是作用域的属性,而是ng-click指令传递的值.

For example you can use ng-click="doSomething($event)", where $event is not an attribute of the scope, but a value passed by the ng-click directive.

您可以使用$locals一次访问所有这些指令,而不必分别访问该指令传递的每个本地"值.

Instead of accessing each "local" value passed by the directive individually, you can have access to all of them at once using $locals.

有关指令的文档:

(重点是我的)

在上述示例中,使用$ locals可以使用该指令传递的整个对象{amount: 22},因此可以使用increment($locals.amount)

In the above axample, the entire object {amount: 22} passed by the directive is available using $locals, and you could thus use increment($locals.amount)

这篇关于AngularJS表达式中的$ locals是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 15:19