2017-05-04 121 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

是的同意,但實際上我更喜歡已經使用驗證的主題,我需要保持它們這就是原因。你有什麼想法,我可以通過類型提交來實現它,只有驗證纔有效。 –

相關問題