0

$scope.form.$setPristine() を使用すると、undefined が返されます。

<html>
    <form name="my_form">
        ...
    </form></html>

$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 に渡そうとしましたが$scope.my_form = $('form');、予想どおり、フォーム オブジェクトを送信したところ、最初のエラーが発生しました。この方法を機能させるには何が必要ですか?

デモ用にプランカーをまとめてみましたが、ルーティングを適切に動作させることができないようです。

ところで、フォームに関する他のすべてが機能します。$setPristine を機能させる方法を知りたいだけです。

4

1 に答える 1

-2

Put the form and the ng-controller at the same level...

<form name="my_form" ng-controller="my_controller">

That's working for me.

(sorry about my english) ;-)

于 2013-10-24T13:11:11.690 に答える