I'm looking for a way to pass an object into a directive, but it turns up as a string.
Given this template:
<div my-directive="{ name: 'Roger', orders: ['apple', 'pie'] }"></div>
How can I get an object back in the directive?
@Input('my-directive') initialData: any; //initial data is a string
I assume maybe something with JSON.parse, but not sure how?
You have to use binding [] syntax
<div [my-directive]="{ name: 'Roger', orders: ['apple', 'pie'] }"></div>
otherwise it is treated a string, and you want object here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With