Ng-submit和ng-click多次触发i ion iPhone应用程序 [英] Ng-submit and ng-click fires many times i ionic iPhone app

查看:119
本文介绍了Ng-submit和ng-click多次触发i ion iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试用离子框架,它看起来非常好。但是,我在表单提交方面遇到问题:表单触发两次。首先按下提交按钮,然后点击屏幕上的任意位置。这在xcode模拟器和我的iphone 4gs上都会发生。

I'm trying out the ionic framework and it looks really nice. However, I have a problem with form submission: the form fires twice. First when the submit button is pressed, and then if I just tap anywhere on the screen. This happens both in the xcode simulator and on my iphone 4gs.

这就是我所做的:
我安装了sidemenu模板:ionic start myApp sidemenu。

This is what I have done: I install the sidemenu template with: ionic start myApp sidemenu.

然后我只需将此表单粘贴到tab-dash模板中:

I then simply paste this form in to the tab-dash template:

  <form ng-submit="createTask(task)">
        <div class="list">
            <label class="item item-input">
                <input type="text" placeholder="What do you need to do?" ng-model="task.title">
            </label>
        </div>
        <div class="padding">
            <button type="submit" class="button button-block button-positive">Create Task</button>

        </div>
    </form>   

在我的控制器中,我只需:

And in my controller I simply have:

 $scope.createTask = function(task) {

        alert(task.title);

    };

这是我对初学者模板所做的唯一更改,但表单仍然提交了两次。我不知道为什么。非常感谢这里的一些指导!

This is the only change I made to the starter template, and still the form submits twice. I have no idea why. Would really appreciate some guidance here!

推荐答案

从按钮中删除type =submit并从中删除ng-submit形成并移动它作为按钮本身的ng点击。

Remove the type="submit" from the button and remove the ng-submit from the form and move it as a ng-click on the button itself.

所以你最终应该

<button ng-click(createTask) class="...">Create Task</button>

这篇关于Ng-submit和ng-click多次触发i ion iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆