AngularJS指令:是否可以在属性中进行插值?

时间:2014-09-21 19:50:17

标签: angularjs angularjs-directive

我有一个我打电话的指令如下:

<photos ng-if="sp.photoZoom" class="alignRight"
    photoid="{{hs.id}}-{{hs.name}}"
    list="[{file: 'rsc/drive/4-Semis/{{hs.id}}-{{hs.name}}/{{hs.tabs[0].photo}}'}]"
    size="256px"
    extension="jpg">
</photos>

听起来是列表,照片没有被插值。

我该怎么办?

[编辑] 指令:

app.directive("photos", function () {
    return {
        restrict: "E",
        replace: true,
        scope: {
            "photoid": "@",
            "scrollable": "@",
            "size": "@",
            "list": "=",
            "inline": "@",
            "extension": "@",
            "class": "@"
        },
        template: 
        '<div id="photos{{photoid}}" class="scroller {{class}}" ng-class="[{{scrollable}}]" ng-style="{display:list.length==1?\'inline-block\':\'block\', width: list.length==1?\'{{size?size:\'171px\'}}\':\'auto\', height: \'{{size?size:\'171px\'}}\'}">\n\
            <div ng-repeat="p in list"\n\
                ng-style="{\'background-image\': \'url({{p.file}}.thumb.{{extension}})\', width: \'{{size?size:\'171px\'}}\', height: \'{{size?size:\'171px\'}}\'}"\n\
                ng-click="$parent.$parent.openPopoverImageViewer(\'#photos{{photoid}}\', {{$index}})">\n\
                <div>{{p.text}}</div>\n\
            </div>\n\
        </div>'
    };
});

1 个答案:

答案 0 :(得分:0)

答案是列表参数(=)要求必须对其进行角度化(如下所示):

<photos
    photoid="{{hs.id}}-{{hs.name}}"
    list="[{file: 'rsc/drive/4-Semis/'+hs.id+'-'+hs.name+'/'+hs.tabs[0].photo, text:hs.tabs[0].displayName}]"
    size="256px"
    extension="jpg">
</photos>