I have a list group which gets data from a rest service using HttpClient Post method.
I get "Cannot find a differ supporting object error" intermittently. But when I refresh the browser the data is displayed and if I try to switch between compoenents, I can still see the data. But after 10 mins or so if I click try to access any component on the page, I get above error.
Below is my code. Can you help me identifying what I am doing wrong?
component.html
<div class="list-group">
<a
routerLinkActive="active"
routerLink="/home/switchroles/{{ account.acc_name }}"
class="list-group-item list-group-item-action pl-1 pr-1 pt-1 pb-0 rounded-0"
*ngFor="let account of allAccounts">{{ account.acc_dname }}
<!--<span class="badge badge-pill badge-dark float-right">{{ account.Roles.length }}</span>-->
</a>
</div>
component.ts
export class SwitchRolesComponent implements OnInit {
allAccounts: Account[] = [];
accountsCount: number;
loading: boolean;
constructor(private http: HttpClient, private dataservice: DataService) {
this.loading = true;
}
ngOnInit() {
this.dataservice.getAllAccounts().subscribe(
res => {
this.allAccounts = res;
this.accountsCount = res.length;
this.loading = false;
},
err => {
console.log('Error Occoured');
console.log(err);
}
);
}
}
getAllAccounts function from a dataservice
getAllAccounts(): Observable<Account[]> {
return this.http.post<Account[]>('https://rest-url/Prod/getdata', {
'operation': 'SelectFromMySQLDB',
'data': {
'query': 'select query here'
}
});
}
Account Class
export class Account {
constructor(
public acc_name: string,
public acc_dname: string,
public acc_number: string,
public acc_roles: string,
public acc_desc: string,
) {}
}
Edit: Pring {{ allAccounts | json }}
[
{
"idawsaccounts": 11,
"acc_name": "test1",
"acc_dname": "Test1",
"acc_number": "123456789",
"acc_roles": "Test roles",
"acc_desc": "Test Desc"
},
{
"idawsaccounts": 12,
"acc_name": "test2",
"acc_dname": "Test2",
"acc_number": "123456789",
"acc_roles": "Test roles",
"acc_desc": "Test Desc"
},
{
"idawsaccounts": 13,
"acc_name": "test3",
"acc_dname": "Test3",
"acc_number": "123456789",
"acc_roles": "Test roles",
"acc_desc": "Test Desc"
}
]
allAccounts
in template with json pipe. Ex: {{allAccounts | json}} and see what happens. Remove all the template. Just printallAccounts
- Ashraful Islam