VSO VSO - 6 months ago 21
HTML Question

Pass Objects To Directive From Html

I have a directive with isolate scope that receives items from its parent:

scope: {
items: '=?items'
}


For example, if I have:

$scope.items = [
{id: 1, description: 'foo'},
{id: 2, description: 'bar'},
]


I can pass it like so:

<my-directive items = "items"></my-directive>


The problem is that I don't always have the items packaged neatly into an object and there are situations where I want to pass random data. For example:

<my-directive items = "[ {id: 5, description: {{someScopeVar.someTextProp}}} ]"></my-directive-items>


The code above does not work. Is it possible to do? Is it ABSOLUTELY horrible practice?

Edit: I just added a new variable on the parent scope which packages what I need into an object wrapped in an array (because directive takes array). This is a purely theoretical question now.

Answer

Edit:

<my-directive items = "[ {id: 5, description: {{someScopeVar.someTextProp}}} ]"></my-directive-items>

To:

<my-directive items = "[ {id: 5, description: someScopeVar.someTextProp} ]"></my-directive-items>