我的代码:
<form role="form" #login="ngForm" (ngSubmit)="onSubmit(login.form)">
<div class="form-group">
<label class="control-label" for="adviserUsername">Username</label>
<input class="form-control" [(ngModel)]="adviserUsername" #username="ngModel" placeholder="Enter Username" type="text" name="adviserUsername"
required>
<div *ngIf="username.touched && username.errors">
<div class="alert alert-danger" *ngIf="username.errors.required">Username is required</div>
</div>
</div>
<div class="form-group">
<label class="control-label" for="password">Password</label>
<input class="form-control" [(ngModel)]="passwordText" #password="ngModel" id="password" name="password" placeholder="Password"
type="password" required>
</div>
<div class="alert alert-danger" *ngIf="password.touched && password.errors">Password is required</div>
<button type="submit" class="btn btn-block btn-lg btn-primary" (click)="login()" [disabled]="!login.valid">Login</button>
</form>
我得到的错误是
答案 0 :(得分:0)
解决方案很简单 我在按钮点击时使用了一个点击事件 - 这是使用login() - 这是双重引用并且产生了一个问题......
代码: 行固定&gt;&gt;
<button type="submit" class="btn btn-block btn-lg btn-primary" [disabled]="!login.valid">Login</button>