相关疑难解决方法(0)

Angular 1.2.1中的$ setPristine()方法似乎没有按预期工作

我正在尝试使用$setPristineAngularJS中的函数重置文本框,但它似乎不会导致所需的行为.

我的表单看起来像这样:

<form name="addInviteForm" ng-controller="InviteCtrl" ng-submit="sendInvitation(userEmail)">

      Pristine? {{addInviteForm.$pristine}}

      <!-- email input -->
      <div>
        <input type="email" name="email" ng-model="userEmail" placeholder="Enter email here"  class="line-item-input see" required>
        <span class="error" ng-show="addInviteForm.email.$error.email" style="color:red">Invalid Email</span>
      </div>

      <!-- submit button -->
      <input type="submit" name="send" class="btn btn-success center" value="Send Invitation">
</form>
Run Code Online (Sandbox Code Playgroud)

和我的控制器中的相应代码:

$scope.sendInvitation = function(userEmail) {

        // do some work here ...

        // hmm, this doesn't seem to work ...
        $scope.addInviteForm.$setPristine();
    };
Run Code Online (Sandbox Code Playgroud)

虽然表单显示$pristine设置为true表单条目,然后设置为false在文本框中输入数据时,在提交表单后它确实显示$pristine设置为true ....然而文本框中的值仍然为它是在按下提交按钮之前.

我在这里错过了什么?

javascript dom angularjs

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

angularjs ×1

dom ×1

javascript ×1