如何从控制器访问?

时间:2015-02-10 08:30:09

标签: javascript angularjs angularjs-ng-form

考虑我有一个表单,ng-form和控制器 -



var myAppModule = angular.module('myApp', []); 
myAppModule.controller('myCtrl',function ($scope) {
          
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<div ng-app="myApp">
    <div ng-controller="myCtrl" ng-form name="myForm">
		Name : <input ng-model="name" type="text" />
    </div>
</div>
&#13;
&#13;
&#13;

我如何才能在控制器中myCtrl访问表单 - myForm

1 个答案:

答案 0 :(得分:1)

$ scope.myForm将具有表单数据

var myAppModule = angular.module('myApp', []); 
myAppModule.controller('myCtrl',function ($scope) {
     var form = $scope.myForm;
});