Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular >2 Dynamic object key causing template parse error

When trying to place a value for a key, with a variable inside of my event binding expression, I am given a template parse error: Parser Error: Unexpected token [, expected identifier, keyword, or string at column... error img my expression is: (ngModelChange)="action.emit({type: 'CACHE_SELECTED_COMPANY', payload: { [selectedCompany.id]:{selected: true, details: false}}})"

I thought that providing a variable name for a key in [square brackets] was allowed, and my question is, should I be able to provide a variable as a key in an Angular 2 template's, event binding expression?

like image 358
Rex Avatar asked Oct 18 '25 03:10

Rex


1 Answers

Computed properties are currently not supported in templates.

Template may be refactored to not use computed properties:

(ngModelChange)="action.emit({type: 'CACHE_SELECTED_COMPANY', payload: getPayload(selectedCompany.id})"

Or entire action.emit(...) may be moved to model change callback.

like image 137
Estus Flask Avatar answered Oct 20 '25 17:10

Estus Flask



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!