I have an input type number set to
<input type="number" ng-model="inputModel"/>
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
See this question - you can use the $root
property on the scope and the binding would be
<input type="number" ng-model="$root.inputModel"/>
This will bind directly on the root scope without the need to explicitly assign it in the controller.
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: ''
}
and
<input type="number" ng-model="fields.inputModel"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With