使用双卷bracer的指令的输入不起作用

Input to a directive using double curly bracers not working

本文关键字:指令 不起作用 输入 bracer      更新时间:2023-09-26

我已经编写了这个指令,它使用d3.js渲染一些星星。当我给它硬编码输入时,它工作得很好,但当我从我的作用域给它输入时,就不工作了。这是我指令的一部分(表现出相同的行为):

   app.directive('stars', function() {
        return {
            scope: {
                width: "@",
                height: "@",
                maxStars: "@",
                filled: "@"
            },
            link: function(scope, element, attrs) {
                console.log(attrs);
                console.log(attrs.filled);
            }
        }
  });

我这样称呼我的指令:

<table ng-app="app" ng-controller="Mainctrl">
    <tbody>
            <tr ng-repeat="agent in data">
                <td stars width="200" height="100" max-stars="5" filled="{{agent.ratings.avg}}"></td>
            </tr>
    </tbody>
</table>

打印属性给我(以及其他值):

filled: "4"
height: "100"
maxStars: "5"
stars: ""
width: "200"

而打印attrs.filled则显示"未定义"。

我发现我可以清楚地看到对象attrs有一个键"filled"的值,但当我试图访问它时,我会得到"undefined"。

这已经在原始帖子的评论中得到了回答。