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>
$rootScope
. But what are accomplishing by doing this? For more information, see AngularJS Developer Guide - Scopes - georgeawgng-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 theng-model
directive with $rootScope. See AngularJS FAQ - $rootScope exists, but it can be used for evil. - georgeawg