如何将对象传递给指令?

时间:2013-06-22 00:05:59

标签: angularjs

我遇到了将对象传递给我的指令的问题。我相信我已经做好了事情,但是在尝试失败后失败后我必须寻求帮助。我在这里想念的是阻止我将数组传递给我的指令吗?

HTML:

<div class="body">
   {{orderList.length}} //shows up as 18
</div>
<queue-summary orders="orderList"></queue-summary>

使用Javascript:

directive('queueSummary', function () {
    return {
        scope: {
            orders: '='
        },
        replace: true,
        restrict: 'E',
        templateUrl: '/partials/admin/bits/queue-summary.htm',
        link: function (scope, element, attrs) {
            console.log(scope, element, attrs); //$attrs.orders show it as the String "orderList" instead of the array
        }
    }
}).

2 个答案:

答案 0 :(得分:2)

值得注意的是,您可以使用$ eval访问您没有隔离范围的属性的绑定值:

scope.$eval(attrs.orders)

答案 1 :(得分:1)

attrs只会显示属性的字符串值。要访问传递的对象,请使用您创建的隔离绑定:

console.log(scope.orders);
相关问题