在 HTML 表中,我檢索SOLDE欄位的值。
<div class="container" *ngIf="details">
<table class="table table-hover table-striped spaceLeft">
<tbody>
<tr>
<th>Solde</th>
<td>{{details[0].SOLDE}}</td>
</tr>
</tbody>
</table>
</div>
這是一張圖片
影像1
除此之外,我必須在輸入中檢索焊接的值并鎖定輸入。
我試圖創建一個表單并添加變數SOLDE來檢索值,但不幸的是它不起作用。
<div class="card-body">
<form #formulaire="ngForm" (ngSubmit)="formulaire.form.valid ">
<div class="row row-cols-3 pt-3">
<div class="col text-end">
<label for="solde" class="form-label">Solde</label>
</div>
<div class="col-4">
<input
id="solde"
name="solde"
type="text"
class="form-control"
style="min-width: 380px"
maxlength="25"
[(ngModel)]="details[0].SOLDE"
/>
</div>
</div>
</form>
</div>
我收到一條錯誤訊息:
Error TS2532: Object is possibly 'undefined'.
我認為問題在這里--> [(ngModel)]="details[0].SOLDE?
請問如何從輸入中檢索值?
目前,component.ts 檔案是這樣的:
export class InternalTransfertWatchComponent implements OnInit, OnDestroy {
private unsubscribe$ = new Subject<void>();
details?: AdvTitres[] = [];
svm: string | null = null;
constructor(
private service: InternalTransfertWatchService,
private activatedRoute: ActivatedRoute,
private location: Location,
) { }
ngOnInit(): void {
this.svm = this.activatedRoute.snapshot.paramMap.get('svm');
if (!this.svm) {
this.goBack();
return;
}
this.getDetails();
}
ngOnDestroy(): void {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
private getDetails(): void {
this.service.getTransfert(this.svm!).pipe(
takeUntil(this.unsubscribe$)
).subscribe(res => {
if (res.RETURNCODE === ApiResponseCodeEnum.Ok) {
this.details = res.TRANS;
}
});
}
goBack(): void {
this.location.back();
}
}
謝謝你的幫助。
uj5u.com熱心網友回復:
對于您的錯誤,您可以使用它
[(ngModel)]="details[0]!.SOLDE"
要鎖定輸入,請將disabled屬性添加到其中。
現在,作為個人意見,如果您顯示始終禁用的輸入,則不需要輸入,文本欄位就可以了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/462380.html
