Hi.
I get this error when I try to get data from Web API using Angular 2
This is the full error message:
ERROR TypeError: Cannot read property 'count' of undefined
at Ajax.fnSuccess [as onSuccess] (manager.js:240)
at Ajax.webpackJsonp.../../../../@syncfusion/ej2-base/dist/es6/ajax.js.Ajax.successHandler (ajax.js:68)
at Ajax.webpackJsonp.../../../../@syncfusion/ej2-base/dist/es6/ajax.js.Ajax.stateChange (ajax.js:95)
at XMLHttpRequest._this.httpRequest.onreadystatechange [as __zone_symbol__ON_PROPERTYreadystatechange] (ajax.js:53)
at XMLHttpRequest.wrapFn (zone.js:1166)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.es5.js:3881)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (zone.js:192)
at ZoneTask.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:499)
This is my .html component code
<ej-grid #gridVacunas [dataSource]='data' [enableHover]="false" [allowSelection]="true" [selectionSettings]="selectOptions">
<e-columns>
<e-column type='checkbox' width='50'>e-column>
<e-column field='codigo' headerText='Código' width='120'>e-column>
<e-column field='nombre' headerText='Nombre' width='250'>e-column>
e-columns>
ej-grid>
This is my .ts component code
import { DataManager, WebApiAdaptor } from '@syncfusion/ej2-data';
[...]
export class FormComponent implements OnInit {
public data: DataManager;
[...]ngOnInit() {
this.selectOptions = { persistSelection: true };
this.data = new DataManager({
url: '/api/vacunas',
adaptor: new WebApiAdaptor
});
}
And this is the API's response
- {items: [,…], count: 18}
- count:18
- items:[,…]
- 0:{id: 1, codigo: "bf", nombre: "Vacuna leishmania", cadencia: 345, cadenciaReal: 365, edadMinima: 6,…}
- 1:{id: 2, codigo: "COR", nombre: "Vacuna coronavirus", cadencia: 345, cadenciaReal: 345, edadMinima: 2,…}
- 2:{id: 3, codigo: "duramu", nombre: "vacuna duramune 8", cadencia: 0, cadenciaReal: 0, edadMinima: 0,…}
- [...]
Thank you.