angularJS NG-模型的输入型数rootScope不更新 [英] angularJS ng-model input type number to rootScope not updating

查看:124
本文介绍了angularJS NG-模型的输入型数rootScope不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须设置为输入类型号

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屋!

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