import { Component , ElementRef , OnInit , ViewChild } from '@angular/core' ; import { RenderFieldComponent } from '../components.fields' ; @ Component ( { templateUrl : './password.component.html' , styleUrls : [ './text.component.scss' ] } ) export class PasswordComponent extends RenderFieldComponent implements OnInit { @ ViewChild ( 'passWordInput' ) public passWordToggle : ElementRef ; public displayType : string = 'text' ; public constructor ( ) { super ( ) ; } public ngOnInit ( ) { if ( this . data . hasOwnProperty ( 'force_hidden' ) && this . data . force_hidden ) { this . displayType = 'password' ; } } public toggleInput ( ) { if ( this . passWordToggle . nativeElement . type === 'password' ) { this . passWordToggle . nativeElement . type = 'text' ; } else { this . passWordToggle . nativeElement . type = 'password' ; } } public generatePassword ( ) { this . passWordToggle . nativeElement . value = Math . random ( ) . toString ( 36 ) . slice ( - 8 ) ; this . controller . setValue ( this . passWordToggle . nativeElement . value ) ; } }