Angular2表单页面重新加载?

时间:2017-05-04 08:58:14

标签: javascript typescript angular2-forms

我正在使用Angular2

无法弄清楚为什么页面会引用:

我的表格:

<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';

声明var $:any; 声明var jQuery:any;

@Component({   选择器:'cat-page',   templateUrl:'。/ login -alpha.html' })

导出类PagesLoginAlpha {

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

}

1 个答案:

答案 0 :(得分:2)

将类型更改为按钮

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

或使用按钮

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