Created
July 9, 2016 15:50
-
-
Save Oipo/ffc61af916e90aa792cb4e5e020c15d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
@Component({ | |
selector: 'login-form', | |
templateUrl: 'app/login-form.html' | |
}) | |
export class LoginFormComponent { | |
submitted = false; | |
error = ''; | |
model = { | |
name: '', | |
password: '' | |
}; | |
onSubmit() { | |
this.submitted = true; | |
} | |
canSubmit() { | |
if(this.model.name === undefined || this.model.name.length <= 3 || this.model.name.length >= 20) { | |
this.error = 'Name has to be at least 4 and at most 20 characters.'; | |
return false; | |
} | |
this.error = undefined; | |
return true; | |
} | |
showError() { | |
return this.error === undefined; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<h1>Login Form</h1> | |
<form> | |
<div class="form-group"> | |
<label for="name">Name</label> | |
<input type="text" class="form-control" required [(ngModel)]="model.name" name="name"> | |
<div *ngIf="showError()">{{error}}</div> | |
</div> | |
<div class="form-group"> | |
<label for="password">Password</label> | |
<input type="text" class="form-control" required [(ngModel)]="model.password" name="password"> | |
</div> | |
<button type="submit" class="btn btn-default" [disabled]="!canSubmit()">Submit</button> | |
</form> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment