angularJS NG-模型的输入型数rootScope不更新 [英] angularJS ng-model input type number to rootScope not updating
问题描述
我必须设置为输入类型号
I have an input type number set to
<input type="number" ng-model="inputModel"/>
其中, inputModel
是 $ rootScope.inputModel
。我每次更改输入框中的值不会保留到 $ rootScope
。难道不能绑定一个输入框到 $ rootScope
?什么我在这里丢失?结果
我基本上有另一个控制器上给出执行计算 $ rootScope
和这些计算的变化取决于什么输入框的值。结果
一个帮助是多少AP preciated搜索结果
谢谢
Where inputModel
is $rootScope.inputModel
. Every time I change the input box the value does not persist onto the $rootScope
. Is it not possible to bind an input box to a $rootScope
? what am I missing here?
I basically have another controller that performs calculations on given $rootScope
and those calculations change depending on what the value of the input box is.
An help is much appreciated
Thanks
推荐答案
正如其他人指出的那样,这是一个典型的继承问题。在当前范围内产生的输入模式,而不是rootScope。
As others pointed out, it is a prototypical inheritance problem. Your input model is generated in the current scope, not the rootScope.
始终使用。在你的看法。这将工作:
Always use "." in your views. This will work:
rootScope.fields = {
inputModel: ''
}
和
<input type="number" ng-model="fields.inputModel"/>
这篇关于angularJS NG-模型的输入型数rootScope不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!