使用双花​​括号输入指令不起作用

时间:2014-10-27 08:18:57

标签: javascript angularjs angularjs-directive angularjs-ng-repeat

我已经写过这个使用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有一个值,因为密钥已填充&#39;但是当我尝试访问它时,我得到了“未定义”。

1 个答案:

答案 0 :(得分:0)

原帖子的评论已经回复了。