我正在尝试使用action 属性 制作一个简单的登录表单。这里的问题是永远不会发送对 /login 的请求。通过开发工具将表单复制并粘贴到 DOM 中,使复制的表单生效。 Angular 似乎阻止了表单的默认行为。
这是我的登录表单组件,非常基础:
@Component({
selector: 'my-app',
template: `
<form #f="ngForm" action="/login" method="POST">
Username: <input type="text"required>
<br/>
Password: <input type="password" required>
<br/>
<button type="submit">Login</button>
</form>
`,
directives: [FORM_DIRECTIVES]
})
我还尝试在 ngSubmit
指令的处理程序中返回 true
/false
但它也不起作用。
这是一个plunker说明问题。
有谁知道如何告诉 Angular 提交带有操作请求的表单?
angular.2.0.0-Beta.1
最佳答案
你可以这样做:
<button type="submit" (click)="f.submit()">Login</button>
或使用 ngNoForm
form
中的属性标记为@Thierry Templier 在此处建议:
关于forms - 提交时 Angular 2 表单不发送操作请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34906983/