2017-05-04 46 views
1

我使用Angular2Angular2表单页面重新加载?

无法弄清楚为什么页面refereshing:

我的表格:

<form> 
         <div class="form-group"> 
          <label class="form-label">Username</label> 
          <input type="email" class="form-control" id="username" placeholder="Email" name="username" /> 
         </div> 
         <div class="form-group"> 
          <label class="form-label">Password</label> 
          <input type="password" class="form-control" id="password" placeholder="Password" name="password" /> 
         </div> 
<input type="submit" class="btn btn-primary mr-3" (click)=onSubmit() /> 


        </form> 

在TS:

import { Component} from '@angular/core'; 

声明变量$:任何; declare var jQuery:any;

@Component({ 选择: '猫页面', templateUrl: './login-alpha.html' })

出口类PagesLoginAlpha {

onSubmit() 
{ 
    console.log("in submittt"); 
} 

}

+0

上点击功能用引号'(点击)= “的onsubmit()”' – mxr7350

+0

没有现在也是其重装。 –

回答

2

更改类型为按钮

<input type="button" class="btn btn-primary mr-3" (click)="onSubmit()" /> 

或者使用按钮

<button type="button" (click)="onSubmit()">submit</button> 
+0

非常感谢现在回复页面不再重新加载,再次感谢很多,但我有一个问题,我的问题是,我正在应用jQuery验证和应用验证我需要提交的形式,我使用类型提交。在我的情况下(ngSubmit)也不能正常工作,你可以请帮助..预先感谢 –

+0

而不是使用jQuery验证使用角度验证 –

+0

是的同意,但实际上我更喜欢已经使用验证的主题,我需要保持它们这就是原因。你有什么想法,我可以通过类型提交来实现它,只有验证才有效。 –