将ng-model与label元素一起使用. [英] Use ng-model with label element.
本文介绍了将ng-model与label元素一起使用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读代码并进入其中将label元素与data-ng-model一起使用的部分,这可能吗?
I am reading a code and got into a part where a label element is been used with data-ng-model is that possible ?
<label class="btn btn-success"
data-ng-model="myController.statusFilter"
data-btn-radio="'disabled'"
data-ng-click="myController.method()">
Disabled
</label>
推荐答案
它不起作用.由于ngModel仅应与输入一起使用,因为它涉及双向数据绑定.
It wont't work. Since ngModel should only be used with the inputs, since it involves two-way data binding.
标签不处理用户输入,因此不需要ngModel.因此,如果要将范围变量绑定到标签,则可以使用 表达式 .
Label does not deal with user input, thus it does not require the ngModel. So if you want to bind a scope variable to the label then you can use expressions.
喜欢
<label> {{labelText}} </label>
注意:您应该在控制器中定义labelText,例如$scope.labelText = "Hello"
这篇关于将ng-model与label元素一起使用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文