& 和有什么不一样vs @ 和 = 在 angularJS 中 [英] What is the difference between & vs @ and = in angularJS

查看:25
本文介绍了& 和有什么不一样vs @ 和 = 在 angularJS 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 AngularJS 很陌生.任何人都可以向我解释这些 AngularJS 运算符之间的区别:&、@ 和 = 当用适当的例子隔离范围时.

I am very new to AngularJS. can anybody explain me the difference among these AngularJS operators: &, @ and = when isolating scope with proper example.

推荐答案

@ 允许将在指令属性上定义的值传递到指令的隔离范围.该值可以是一个简单的字符串值 (myattr="hello"),也可以是一个带有嵌入表达式的 AngularJS 内插字符串 (myattr="my_{{helloText}}">).将其视为从父作用域到子指令的单向"通信.John Lindquist 有一系列简短的截屏视频来解释其中的每一个.@ 上的截屏视频在这里:https://egghead.io/lessons/angularjs-isolate-scope-attribute-binding

@ allows a value defined on the directive attribute to be passed to the directive's isolate scope. The value could be a simple string value (myattr="hello") or it could be an AngularJS interpolated string with embedded expressions (myattr="my_{{helloText}}"). Think of it as "one-way" communication from the parent scope into the child directive. John Lindquist has a series of short screencasts explaining each of these. Screencast on @ is here: https://egghead.io/lessons/angularjs-isolate-scope-attribute-binding

& 允许指令的隔离作用域将值传递到父作用域中,以便在属性中定义的表达式中求值.请注意,指令属性是隐式表达式,不使用双花括号表达式语法.这个更难用文字解释.截屏视频在这里:https://egghead.io/lessons/angularjs-isolate-scope-表达式绑定

& allows the directive's isolate scope to pass values into the parent scope for evaluation in the expression defined in the attribute. Note that the directive attribute is implicitly an expression and does not use double curly brace expression syntax. This one is tougher to explain in text. Screencast on & is here: https://egghead.io/lessons/angularjs-isolate-scope-expression-binding

= 在指令的隔离作用域和父作用域之间设置双向绑定表达式.子作用域中的更改会传播到父作用域,反之亦然.将 = 视为 @ 和 & 的组合.= 上的截屏视频在这里:https://egghead.io/lessons/angularjs-isolate-scope-two-way-binding

= sets up a two-way binding expression between the directive's isolate scope and the parent scope. Changes in the child scope are propagated to the parent and vice-versa. Think of = as a combination of @ and &. Screencast on = is here: https://egghead.io/lessons/angularjs-isolate-scope-two-way-binding

最后是一个截屏视频,在一个视图中显示了所有三个一起使用的情况:https://egghead.io/lessons/angularjs-isolate-scope-review

And finally here is a screencast that shows all three used together in a single view: https://egghead.io/lessons/angularjs-isolate-scope-review

这篇关于& 和有什么不一样vs @ 和 = 在 angularJS 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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