Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 将带表达式的字符串传递给指令并在模板中解析_Angularjs_Angularjs Directive - Fatal编程技术网

Angularjs 将带表达式的字符串传递给指令并在模板中解析

Angularjs 将带表达式的字符串传递给指令并在模板中解析,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我试图转换一个字符串,其中包含一个通过属性传递的表达式,在own指令的模板中。我们的想法是这样做: <div custom-directive images-source="'staticpath/blah/blah/{{Item.Src}}'"></div> <ul> <li ng-repeat="Item in Items"> <img ng-src="{{imagesSource}}{{Item.name}}.

我试图转换一个字符串,其中包含一个通过属性传递的表达式,在own指令的模板中。我们的想法是这样做:

<div custom-directive images-source="'staticpath/blah/blah/{{Item.Src}}'"></div>
<ul>
    <li ng-repeat="Item in Items">
        <img ng-src="{{imagesSource}}{{Item.name}}.{{Item.extension}}" />
    </li>
</ul>
<ul>
    <li ng-repeat="Item in Items">
        <img ng-src="staticpath/blah/blah/src1/file1.jpg" />
        <img ng-src="staticpath/blah/blah/src2/file2.jpg" />
        <img ng-src="staticpath/blah/blah/src3/file3.jpg" />
        <img ng-src="staticpath/blah/blah/src4/file4.jpg" />
    </li>
</ul>
有什么想法吗

编辑: 想象下一个场景。我们有一个指令,将显示图像库的列表。每个图像库将有:一个标题,一个小说明和从1到n个图像

好的,假设我们有一个常量,根指向images文件夹“/media/images/gallers/”。然后,在模板内部,在ngRepeat循环中,我需要使用该常量和一个属性(在本例中,我们可以将其命名为“subfolder”)构建路径,但我不希望自己的指令决定需要哪个属性。(这就是我希望在属性中传递表达式的原因)

该指令:

<div image-galeries images-source="'staticpath/blah/blah/{{Gallery.subfolder}}'">

模板:

<div ng-repeat="Gallery in Galleries">
    <h3>{{Gallery.title}}</h3>
    <p>{{Gallery.description}}</p>
    <ul>
        <li ng-repeat="Image in Gallery.Images">
            <img ng-src="{{imagesSource}}{{Image.name}}.{{Image.extension}}" />
        </li>
    </ul>
</div>

{{Gallery.title}
{{Gallery.description}

结果是:

<div ng-repeat="Gallery in Galleries">
    <h3>Gallery 1</h3>
    <p>Gallery description 1</p>
    <ul>
        <li ng-repeat="Image in Gallery.Images">
            <img ng-src="staticpath/blah/blah/src1/file1.jpg" />
            <img ng-src="staticpath/blah/blah/src1/file2.jpg" />
            <img ng-src="staticpath/blah/blah/src1/file3.jpg" />
            <img ng-src="staticpath/blah/blah/src1/file4.jpg" />
        </li>
    </ul>
</div>
<div ng-repeat="Gallery in Galleries">
    <h3>Gallery 2</h3>
    <p>Gallery description 2</p>
    <ul>
        <li ng-repeat="Image in Gallery.Images">
            <img ng-src="staticpath/blah/blah/src2/file1.jpg" />
            <img ng-src="staticpath/blah/blah/src2/file2.jpg" />
        </li>
    </ul>
</div>

画廊1
画廊简介1

画廊2 画廊简介2

请原谅,关于我的英语,我希望它足够清楚:D

<div ng-repeat="Gallery in Galleries">
    <h3>Gallery 1</h3>
    <p>Gallery description 1</p>
    <ul>
        <li ng-repeat="Image in Gallery.Images">
            <img ng-src="staticpath/blah/blah/src1/file1.jpg" />
            <img ng-src="staticpath/blah/blah/src1/file2.jpg" />
            <img ng-src="staticpath/blah/blah/src1/file3.jpg" />
            <img ng-src="staticpath/blah/blah/src1/file4.jpg" />
        </li>
    </ul>
</div>
<div ng-repeat="Gallery in Galleries">
    <h3>Gallery 2</h3>
    <p>Gallery description 2</p>
    <ul>
        <li ng-repeat="Image in Gallery.Images">
            <img ng-src="staticpath/blah/blah/src2/file1.jpg" />
            <img ng-src="staticpath/blah/blah/src2/file2.jpg" />
        </li>
    </ul>
</div>