With angular, I am getting data as follows through the api. Everything works very well, but I cannot place the incoming json object into the model. I can't find where I made a mistake. Can you provide support?
export class DialogBoxComponent implements OnInit {
workflows: WorkflowListModel[] = [];
constructor(
public workflowService: WorkflowListService
) {
}
ngOnInit(): void {
this.workflowService.getWorkflowDefinitions().subscribe(data => {
this.workflows = data.items;
console.log(this.workflows);
});
}
Service
public getWorkflowDefinitions(){
let api = `${this.apiUrl}/services/workflows`;
return this.httpClient.get<{items: WorkflowListModel[]}>(api).pipe(tap(x =>{
this.loading = false;
console.log();
}));
}
Model
export class WorkflowListModel {
id: string | any;
definitionId: string | any;
name: string | any;
displayName: string | any;
description: string | any;
version: number | any;
persistenceBehavior: string | any;
isPublished: string | any;
isLatest: string | any;
}
json-result
[
{
"id": "fb40d5c146644e58b05e2cb573409bbc",
"definitionId": "336507c20553401f85d3b2b4e11a562c",
"name": "demand",
"displayName": "demand",
"description": "demand",
"version": 1,
"isSingleton": false,
"persistenceBehavior": "Suspended",
"isPublished": true,
"isLatest": true
}
]
HTML
<input type="text" placeholder="{{action}}" matInput [formControl]="myControl"
[matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of filteredOptions" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
this way a json object comes and i can access the items in this object
{
"items": [
{
"id": "fb40d5c146644e58b05e2cb573409bbc",
"definitionId": "336507c20553401f85d3b2b4e11a562c",
"name": "demand",
"displayName": "demand",
"description": "demand",
"version": 1,
"isSingleton": false,
"persistenceBehavior": "Suspended",
"isPublished": true,
"isLatest": true
}
],
"totalCount": 1
}
