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

标签 javascript angularjs ionic-framework

我有一个奇怪的问题。当我清除 Controller 中的模型时,提交表单时,使用 ng-model 绑定(bind)到模型的输入字段将不会清除。

Controller

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 在输入值更改后引用不同的范围。请参阅this SO answer以获得更深入的解释。

关于javascript - 使用 Ionic 框架在 AngularJS 中提交表单后输入不会清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27034797/

相关文章:

javascript - 如何修复 html 输入类型 = 'number' 中超过最大值的输入?

javascript - ion-view 没有出现在 ion-nav-view 中

javascript - 在 Cordova/ionic 中写入文件不起作用

reactjs - 如何使用 ionic v4 添加自定义 webpack 配置并使用react?

javascript - 调用toggle() 时,paper-dialog 和paper-transition-center 不显示

javascript - iOS 5 Safari 中导航后退/卸载事件未触发时出现页面缓存问题

javascript - 如何使用jQuery更新数据库而不刷新页面?

javascript - 如何将数组值迭代到另一个数组的所有元素

javascript - 如何在 AngularJs 中从另一个 Controller 访问一个 Controller

javascript - 当 td 有多个项目时更新 Angular 表中的行