<div class="input-field col s12">
<input formControlName="client_id" id="client_id" matInput placeholder="Select Client*" aria-label="State" [matAutocomplete]="auto"
autoActiveFirstOption [formControl]="client_id">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayWith" >
<mat-option (onSelectionChange)="updateClient($event, item.client_id, 'client_id')" *ngFor="let item of filteredOptionsClient | async"
[value]="item.clientName">
{{ item.clientName }}
</mat-option>
</mat-autocomplete>
</div>
<div class="input-field col s12">
Contact No:
<span style="color:darkblue">{{selectedClient.contactno}}</span>
</div>
filteredOptionsClient: any;
client_id: FormControl = new FormControl();
ngOnInit() {
this.cs.getAllClients().subscribe(
client => {
this.client = client.map((clients) => {
this.filteredOptionsClient = this.client_id.valueChanges.pipe(
startWith(''),
map(val => this.filterClient(val))
);
return new Client(clients);
});
}
}
);
}
updateClient(ev: any, idd: any, componentid: any) {
if (ev.isUserInput) {
if (componentid === 'client_id') {
this.clientid = idd;
console.log('idd', idd)
this.addsale['controls']['client_id'].setValue(ev.source.value);
} else {
console.log('ooops');
}
}
let selectedClient = new Client('')
this.selectedClient = null;
for (let i = 0; i < this.client.length; i++) {
console.log('updateclient', this.client[i].client_id)
console.log('updateclientidd', idd)
if (this.client[i].client_id === idd) {
this.selectedClient = this.client[i];
}
}
}
您好,我需要在html中显示小数点后2位的值。例如,当0时我需要显示0.00。可以吗? Stackblitz链接-https://stackblitz.com/edit/angular-4cm9yr
答案 0 :(得分:1)
使用.toFixed(小数)
(0).toFixed(2); -> 0.00