重置与$ setPristine角形式 [英] Reset angular form with $setPristine
问题描述
使用$ scope.form。$ setPristine()返回undefined。
Using $scope.form.$setPristine() returns undefined.
<html>
<form name="my_form">
...
</form></html>
定义控制器上的我的$ routeProvider
Defining the controller on my $routeProvider
.when('page_name', {
templateUrl: '...',
controller: function($scope) {
console.log(my_form); // returns the form object
my_form.$setPristine(); returns Object #<HTMLFormElement> has no method '$setPristine'
console.log($scope.my_form); // returns undefined
$scope.my_form.$setPristine(); // returns Cannot call method '$setPristine' of undefined
}
}
我也试过路过的形式通过jQuery的$范围 $ scope.my_form = $('形式');
其中,符合市场预期,刚送来的窗体对象和导致的第一个错误。怎样才能得到这个方法来工作?
I've also tried passing the form to the $scope via jQuery $scope.my_form = $('form');
which, as expected, just sent the form object and resulted in the first error. What does it take to get this method to work?
我试图把一个Plunker一起展示,但我似乎无法得到路由到在那里正常工作。
I tried putting a Plunker together to demonstrate but I can't seem to get routing to work on there properly.
对于其他形式的一切工作BTW。我只是想知道如何获得$ setPristine工作。
Everything else about the form works btw. I would just like to know how to get $setPristine to work.
推荐答案
把形式和NG-控制器在同一水平...
Put the form and the ng-controller at the same level...
<form name="my_form" ng-controller="my_controller">
这是为我工作。
(我的英语对不起); - )
(sorry about my english) ;-)
这篇关于重置与$ setPristine角形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!