Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form noValidate (ngSubmit)="onSubmit(login)" [formGroup]="login">
- Username:<br> <input type="text" formControlName="username"><br>
- <div class="error"
- *ngIf="login.get('username').hasError('required') && login.get('username').touched">
- Username required</div>
- Password:<br> <input type="password" formControlName="password"><br>
- <div class="error"
- *ngIf="login.get('password').hasError('required') && login.get('password').touched">
- Password required</div>
- <br> <input type="submit" value="Login" [disabled]="login.invalid">
- export class LoginComponent implements OnInit {
- login: FormGroup;
- response: ResponseInterface;
- constructor() {
- }
- ngOnInit() {
- this.login = new FormGroup({
- username: new FormControl('', [Validators.required, Validators.required]),
- password: new FormControl('', [Validators.required, Validators.required])});
- }
- onSubmit({ value, valid }: { value: LoginInterface, valid: boolean }) {
- console.log(value, valid);
- }
- }
- export interface LoginInterface {
- username: String;
- password: String;
- }
- export class DropdownosComponent {
- private list = [
- { id: 1, name: 'ONE' },
- { id: 2, name: 'TWO' },
- { id: 3, name: 'THREE'}
- ];
- private current: number = 1;
- private setCurrent(id: number): void {
- this.current = id;
- }
- public getCurrent(): string {
- return this.list.find((item: any) => item.id == this.current).name;
- }
- }
- <select #select [(ngModel)]="current"
- (change)="setCurrent(select.value)">
- <option *ngFor="let item of list" [value]="item.id">{{item.name}}</option>
- </select>
- export interface LoginInterface {
- username: String;
- password: String;
- dropdown: String;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement