设置标记的角度范围变 [英] set angular scope variable in markup
问题描述
简单的问题。我怎么能在html中设置一个范围值,在我的控制器阅读?
Simple question. How can I set a scope value in html, to read in my controller?
<div ng-controller="MyController">
<div name='my_map' scope-myVar='Richmond,VA' scope-someOther='test'>
</div>
</div>
#controller
MyController = function($scope){
alert($scope.myVar)
};
的jsfiddle: http://jsfiddle.net/ncapito/YdQcX/
推荐答案
NG-INIT
不,当你在里面循环分配变量工作。使用 {{MYVARIABLE =什么;}}
ng-init
does not work when you are assigning variables inside loop. Use
{{myVariable=whatever;""}}
尾随,
停止角前pression被评估到任何文本。
The trailing ""
stops the Angular expression being evaluated to any text.
然后,你可以简单地调用 {{} MYVARIABLE}
来输出你的变量值。
Then you can simply call {{myVariable}}
to output your variable value.
我遍历多个嵌套阵列时,发现了这个非常有用,我想保持在一个变量我当前迭代的信息,而不是多次查询吧。
I found this very useful when iterating multiple nested arrays and I wanted to keep my current iteration info in one variable instead of querying it multiple times.
这篇关于设置标记的角度范围变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!