在表单提交的网址中间添加了问号 [英] question mark added in middle of url on form submit

查看:77
本文介绍了在表单提交的网址中间添加了问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击表单中的提交按钮时,它会添加一个?在#so/app/#/pageName更改为/app/?#/pageName之前.这是正常行为吗?代码只是基本的东西.

When I click the submit button in a form it is adding a ? right before the # so /app/#/pageName changes into /app/?#/pageName. Is this normal behavior? Code is just basic stuff.

angular.module('myApp', [])
.controller('MyCtrl', function ($scope) {
    $scope.submit = function() {

    };
});

<form ng-controller="MyCtrl" ng-submit="submit()">
    <button>Submit</button>
</form>

推荐答案

我终于找到了答案,这要感谢

I finally found the answer thanks to Angular JS does not allow preventDefault or return false to work on form submission.

在ng-submit中,我必须添加$ event作为将事件传递到我的Submit函数的参数,然后我可以执行event.preventDefault()来防止路由更改.不确定这是角度错误还是预期的行为,但希望这会对其他人有所帮助.

in my ng-submit I had to add $event as parameter which passed the event to my submit function and I was then able to do event.preventDefault() to prevent the route from changing. Not sure if this is a bug in angular or if it's intended behaviour but hopefully this will help someone else.

这是固定代码:

angular.module('myApp', [])
.controller('MyCtrl', function ($scope) {
    $scope.submit = function(event) {
        event.preventDefault();
    };
});

<form ng-controller="MyCtrl" ng-submit="submit($event)">
    <button>Submit</button>
</form>

这篇关于在表单提交的网址中间添加了问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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