Reputation: 118
im working on a angular project in a certain field im getting password and displaying it on front end i want to hide that text into password field eg "****" like this can anyone help me with the code please ?
details.component.html
<div class="ui-g-12 ui-md-12" >
<div class="ui-g-5 ui-md-5 ui-md-nopad ui-g-nopad">Password</div>
<div class="ui-g-1 ui-md-1 ui-md-nopad ui-g-nopad">:</div>
<div class="ui-g-6 ui-md-6 ui-md-nopad ui-g-nopad" style="text-transform:none">
{{agentdata?.password?agentdata?.password:"Notavailable"}}</div>
</div>
Upvotes: 1
Views: 100
Reputation: 878
or you can pass a boolean and valid it on front-end as below,
{{agentdata?.password?agentdata?.password === true? '******' :"Notavailable"}}
Upvotes: 0
Reputation: 4182
If you do not want input box, you can do it with pipe.
mask-value.pipe.ts:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'maskValue'
})
export class MaskValuePipe implements PipeTransform {
transform(value: string): any {
if (value == null || value.length === 0) {
return value;
}
return '*'.repeat(value.length);
}
}
html
<div class="ui-g-6 ui-md-6 ui-md-nopad ui-g-nopad" style="text-transform:none">
{{agentdata?.password?agentdata?.password | maskValue }}</div>
Upvotes: 0
Reputation: 877
You may have to use an input
element for hiding password.
<input type="password" value="Password">
Provide your password text to the value
attribute of input
element.
Upvotes: 1