1

I have the following directive:

var productsTable = function() {
    return {
        restrict: 'E',

        scope: {
            products: '@'
        },

        templateUrl: '../js/app/templates/products_table.html'
    };
};

The template is a simple table:

<table class="table table-striped">
    <thead>
        <tr>
            <th>#</th>
            <th>Name</th>
            <th>Quantity</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="product in products track by $index">
            <td><% product.id %></td>
            <td><% product.name %></td>
            <td><% product.quantity %></td>
        </tr>
    </tbody>
</table>

And it is used inside this piece of code:

<div ng-controller="MainController">
    <div ng-repeat="entry in entries">
        <products-table products="entry.products"></products-table>
    </div>
</div>

An example of the entries variable would be:

var entries = [
    {
        id: 1,
        products: [
            {
                id: 1001,
                name: 'Product 1',
                quantity: 30
            },
            {
                id: 1002,
                name: 'Product 2',
                quantity: 3
            }
        ]
    },
    {
        id: 2,
        products: [
            {
                id: 3001,
                name: 'Product 3',
                quantity: 450
            }
        ]
    }
];

The problem is: the directive does not recognize the products array, and does not show the table.

Victor Leal
  • 1,055
  • 2
  • 12
  • 28

2 Answers2

2

Try this

scope: {
   products: '='
},

also in Angular you should use {{ }} instead of <% %>

Example

Oleksandr T.
  • 76,493
  • 17
  • 173
  • 144
  • I've got the point here: http://stackoverflow.com/questions/14050195/angularjs-what-is-the-difference-between-and-in-directive-scope – Victor Leal Oct 21 '15 at 18:41
0

You can also use ng-bind="{{variable name}}" in place of {{}} as an attribute in td