Jester Jester - 6 months ago 24
AngularJS Question

pass object to directive

I would like to do the following:

<my-directive my-object="{Code:'test'}"/>


Then convert the string to an object in the controller.
Currently using JSON.parse

I know I can do this:

<my-directive my-object="{&quot;Code&quot;:&quot;test&quot;}"/>


But seems messy and hard to read

Any way to do this?

Answer

It's not pretty, but it is valid to simply do:

<my-directive my-object='{"Code":"test"}'/>