VSO VSO - 7 months ago 35
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.



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


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