包括内部重复

时间:2015-06-17 17:35:43

标签: javascript html angularjs

我正在尝试将ng-include包含在ng-repeat中。但没有任何反应。如果我静态地将它包含在整个链接中就可以了。还试过ng-src但也没用。

的index.html

<div ng-controller="sliderCtrl">
    <div ng-repeat="slide in slides">
        <div ng-include src="'/partials/slider/{{slide.image}}.html'"></div>
     </div>
</div>

sliderCtrl.js

MyApp.controller('sliderCtrl', function ($scope) {
    $scope.slides = [
    {image: '01', description: 'Image 00'},
    {image: '02', description: 'Image 01'},
    {image: '03', description: 'Image 02'}
    ];
});

控制台

Error: [$interpolate:noconcat] http://errors.angularjs.org/1.3.15/$interpolate/noconcat?p0='%2Fpartials%2Fslider%2F%7B%7Bslide.image%7D%7D.html'
    at Error (native)
    at http://192.168.33.77/bower_components/angular/angular.min.js:6:417
    at g (http://192.168.33.77/bower_components/angular/angular.min.js:88:436)
    at Oa (http://192.168.33.77/bower_components/angular/angular.min.js:68:208)
    at X (http://192.168.33.77/bower_components/angular/angular.min.js:53:397)
    at S (http://192.168.33.77/bower_components/angular/angular.min.js:51:428)
    at S (http://192.168.33.77/bower_components/angular/angular.min.js:52:95)
    at D (http://192.168.33.77/bower_components/angular/angular.min.js:49:467)
    at fa (http://192.168.33.77/bower_components/angular/angular.min.js:61:43)
    at S (http://192.168.33.77/bower_components/angular/angular.min.js:51:465) <div ng-view="" class="page ng-scope">

提前致谢!

3 个答案:

答案 0 :(得分:2)

而不是:

<div ng-include src="'/partials/slider/{{slide.image}}.html'"></div>

使用此:

<div ng-include src="'/partials/slider/' + slide.image + '.html'"></div>

答案 1 :(得分:1)

尝试使用data-ng-include data-src:

<div ng-controller="sliderCtrl">
    <div ng-repeat="slide in slides">
        <div data-ng-include data-src="'/partials/slider/{{slide.image}}.html'"></div>
     </div>
</div>

答案 2 :(得分:0)

你忘了逃避内在的引语:

<div ng-controller="sliderCtrl">
    <div ng-repeat="slide in slides">
        <div ng-include src="\'/partials/slider/{{slide.image}}.html\'"></div>
     </div>
</div>