Currently, I am implementing Angular and attempting to iterate through an object.
Data in JSON format
employee {"fName":"mike","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ebb3b3b3b3b3b3b3b3ab83849f868a8287c5888486">[email protected]</a>"}
Definition of interface
export interface Employee {
fName:string
email:string
}
Component Implementation
iEmployee: Employee[];
getITIMDATA() {
this._ersaDet.getITIMData(this.ersaGlobalUID)
.subscribe(
data => {
this.iEmployee = data;
},
error => 'GetAllCostCenetrs Method: ');
}
HTML Template
<div *ngFor="let itim of iEmployee">
<div class="col-lg-12">
<div class="row">
<div class="form-group">
<label class="control-label">Name</label>
<input type="text" name="Name" class="form-control" id="ntName" [(ngModel)]="itim.fName">
</div>
</div>
</div>
<div>
A common error encountered while running the code is:
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.