0
我正嘗試使用組件選擇器顯示數組值,但未成功。目前,組件選擇器將顯示模板/模型中的每個值。我想顯示模型的單個值(稅)。Angular 2 - 使用組件選擇器來顯示json數組值
userAccount.component.html
<div *ngFor="let userAccount of UserAccounts" [class.active]="userAccount === selectedUser" (click)="onSelect(userAcccount)">
<div class= 'col-md-12'>
<input class = "form-control"[(ngModel)] = "userAccount.firstName" placeholder= "First Name" />
<input class = "form-control"[(ngModel)] = "userAccount.LastName" placeholder= "Last Name" />
<input class = "form-control"[(ngModel)] = "userAccount.email" placeholder= "Email" />
<br> <div class= 'col-md-12'>Region</div> <hr>
<input class = "form-control"[(ngModel)] = "userAccount.region" placeholder= "Region" />
<input class = "form-control"[(ngModel)] = "userAccount.taxes" placeholder= "Tax Rate" />
<br>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<br>
<button (click)="goBack()" class="btn btn-default">Back</button>
<button (click)="save()" class="btn btn-primary">Save</button>
</div>
估計,detail.component.html
<tr *ngFor ="let userAccount of UserAccounts">
<td class="table-borderless" colSpan="4" class="text-right"><b>Tax</b></td>
<app-userAccount>{{userAccount.taxes}}</app-userAccount>
</tr>
我想你正在使用組件的{{userAccount.taxes}}'。你可以使用'{{userAccount.taxes}}'而不是' {{userAccount.taxes}} app-userAccount>' –
目前你的問題還不清楚(至少對我而言)。你能否向你的問題添加當前產量以及預期產量。 – Alex
@Jijo Cleetus相信與否,我嘗試過,最初並不起作用,但現在它起作用了。謝謝。 –