0
votes

Please help me to get the data from text box to a controller without embedding controller inside element

<html ng-app="mymod">
<head>
    <script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
    </script>
</head>
<body>
<input ng-model="var1" type="number" /> //Where is this data being stored


<div data-ng-controller="mycont">
    <p data-ng-bind="var3"></p>
</div>
<script>
var mod1 = angular.module("mymod",[]);
mod1.controller('mycont',function($rootScope) {

$rootScope.var3= $rootScope.var1;
})
</script>

</body>

</html>
In the absence of a controller, the data is stored on $rootScope. But what are accomplishing by doing this? For more information, see AngularJS Developer Guide - Scopes - georgeawg
<input ng-model="var1" type="number" ng-change="var3=val1"/> - twitch
@georgeawg , I am learning AngularJS..learning about scopes but am not able to access the $rootScope variable inside the controller. Not trying to accomplish anything out of this ...just for practice ..thanks for the link and reply - Hemanth Sharma
The ng-model directive adds the variable to scope only after the user enters input. The controller is attempting to access that variable before it is created. I can't write an answer that is useful to other readers because I don't recommend using the ng-model directive with $rootScope. See AngularJS FAQ - $rootScope exists, but it can be used for evil. - georgeawg