角度指令 将属性解释为字符串

Angular Directive Interpreting attribute as string

本文关键字:解释 字符串 属性 指令      更新时间:2023-09-26

我的指令如下

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);