Hi. I am trying to create a object with matcher.bind and I am getting this error. I am using the same code as in guide.
Error:
Uncaught TypeError: Cannot read property ‘id’ of null
at App.productMatcher (webpack-internal:///app:11)
at _loop (webpack-internal:///./node_modules/aurelia-binding/dist/native-modules/aurelia-binding.js:4264)
at SelectValueObserver.synchronizeOptions (webpack-internal:///./node_modules/aurelia-binding/dist/native-modules/aurelia-binding.js:4268)
at MutationObserver.eval (webpack-internal:///./node_modules/aurelia-binding/dist/native-modules/aurelia-binding.js:4379)
Code used. Copied from guide.
export interface IProduct {
id: number;
name: string;
}
export class App {
message=“This is Aurelia”;
products: IProduct[] = [
{ id: 0, name: ‘Motherboard’ },
{ id: 1, name: ‘CPU’ },
{ id: 2, name: ‘Memory’ },
];
productMatcher = (a, b) => a.id === b.id;
selectedProduct: IProduct = { id: 1, name: ‘CPU’ };
}
Template used: copied from guide
Select product:Choose... ${product.id} - ${product.name}
Selected product: {selectedProduct.id} - {selectedProduct.name}
** I tried this in javascript and NO error. Error only in TypeScript.
Thanks