Last active
July 19, 2017 13:57
-
-
Save BenevidesLecontes/29ccc598df11de7b0235514fd2ecdc32 to your computer and use it in GitHub Desktop.
Password component
This file contains hidden or 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, ElementRef, Input, ViewChild, ViewEncapsulation} from '@angular/core'; | |
import {FormGroup} from '@angular/forms'; | |
@Component({ | |
selector: 'wi-password', | |
templateUrl: './password.component.html', | |
styleUrls: ['./password.component.scss'], | |
encapsulation: ViewEncapsulation.None | |
}) | |
export class PasswordComponent { | |
@Input() form: FormGroup; | |
@Input() itemName: string; | |
@Input() styles: string | Array<string>; | |
@Input() id = 'password'; | |
@Input() placeholder = 'Senha'; | |
public inputType = 'password'; | |
@ViewChild('eyeElement') eyeElement: ElementRef; | |
public showPassword = false; | |
constructor() { | |
} | |
toggleEye() { | |
if (this.inputType === 'password') { | |
this.showPassword = true; | |
this.inputType = 'text'; | |
} else { | |
this.showPassword = false; | |
this.inputType = 'password'; | |
} | |
}; | |
} |
This file contains hidden or 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="form-group password" *ngIf="form" [formGroup]="form"> | |
<input | |
[id]="id" | |
[ngClass]="styles" | |
name="password" | |
class="form-control" | |
[attr.type]="inputType" | |
[placeholder]="placeholder" | |
autocomplete="false" | |
[formControlName]="itemName"> | |
<a *ngIf="form.get(itemName).value" #eyeElement (click)="toggleEye()" class="toggle icon" | |
[ngClass]="{'icon-eye-open': form.get(itemName).value && !showPassword, | |
'icon-eye-close':form.get(itemName).value && showPassword}"></a> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment