Angular 指令将属性解释为字符串

Angular Directive Interpreting attribute as string

我的指令如下

angular
    .module('app.directives')
    .directive('myTable',function(){

        function linkFn(
            scope,
            element,
            attrs
            ) {

            console.log(attrs.attributes);

        }

        return {
            link: linkFn,
            template: 'some.html',
            scope: {
                attributes: '=',
            },
            replace : true
        }
    });

并且我将指令用作

<my-table attributes="management.table.attributes"></my-table>

但是 link 函数中的 attrs.attribute 值解析为字符串 management.table.attributes,而不是数组。

我将不胜感激任何形式的帮助或指导。

谢谢!

attrs.attribute 总是一个字符串,因为根据定义属性是字符串。您需要相应的 scope.attributes 将被评估对象引用:

console.log(scope.attributes);