'ng-model'指令在哪里存储数据?我无法在控制器内访问它

时间:2017-04-22 18:03:51

标签: angularjs angularjs-scope angularjs-controller

请帮助我将文本框中的数据传输到控制器,而无需在元素中嵌入控制器

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

0 个答案:

没有答案