Jester Jester - 1 year ago 122
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 Source

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

<my-directive my-object='{"Code":"test"}'/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download