使用Ionic框架在AngularJS中提交表单后,输入不会清除

Input won't clear after form submission in AngularJS using Ionic framework

本文关键字:输入 清除 表单 提交 框架 Ionic AngularJS 使用      更新时间:2023-09-26

我有这个奇怪的问题。当我清除控制器中的模型时,使用 ng-model 绑定到模型的输入字段在提交表单时不会清除。

控制器

angular.module('starter.controllers', [])
.controller('DashCtrl', ["$scope", function($scope) {
    $scope.clearInput = function() {
      console.log("I get there...");
      //Here's the issue!!! It's not working as expected!
      $scope.message = "";
    };
}]);

模板

<ion-view title="Dashboard">
    <ion-content class="padding">
        <form name="myform" ng-submit="clearInput()">
            <label class="item item-input">
                <input type="text" ng-model="message"/>
            </label>
            <button type="submit" class="button button-positive" >
                button-positive
            </button>
        </form>
    </ion-content>
</ion-view>

得到控制台输出"我到达那里",因此该功能被激活。我在这里错过了什么?

clearInput()ng-model在输入值更改后引用不同的范围。请参阅此SO答案以获取更深入的解释。