Cannot read property 'name' of undefined at valuePrepareFunction
- Dominant language
- TypeScript
- Stars
- 1.6k
- Forks
- 867
- PR merge metrics
- No merged PRs in 30d
Description
Hello..
I have an object that contains a code property that is stored in the database, but its name does not exist in the database, so I need to find the name through the search code at options list . I used the following method , the data in the table is displayed correctly, but when loaded the page ,a lot of the following error are displayed in the console:
```
ERROR TypeError: Cannot read property 'name' of undefined
at valuePrepareFunction (example.component.ts:716)
at Cell.push../node_modules/ng2-smart-table/lib/data-set/cell.js.Cell.getValue (cell.js:19)
at Object.eval [as updateRenderer] (ViewCellComponent.html:5)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:11948)
at checkAndUpdateView (core.js:11320)
at callViewAction (core.js:11556)
at execEmbeddedViewsAction (core.js:11519)
at checkAndUpdateView (core.js:11316)
at callViewAction (core.js:11556)
at execComponentViewsAction (core.js:11498)
```
**My options:**
```
this.options = [
{ name: 'Mary',code:1 },
{ name: 'Shelley',code:2 },
{ name: 'Igor',code:3 }
];
```
**My setting :**
```
settings = {
columns: {
objectCode: {
title: 'name',
type: 'string',
valuePrepareFunction: (code) => (code) ? this.options
.filter(object => object.code == code)[0].name : ""
}
}
}
```
**The data format assigned to the source:**
```
data = {
objectCode:1,
id:10,
...
}
ngOnInit() {
this.source.load(this.data);
}
```
Please help me!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.