我的指令如下

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>


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

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

谢谢!

最佳答案

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

console.log(scope.attributes);

关于javascript - Angular Directive(指令)解释属性为字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27798994/

10-12 15:09