2015-07-21 31 views
2

编辑: TIL你不需要在范围中添加url。另外,要小心钥匙,谢谢。以角js图像的URL

我想表现出一个HTML5文档一些图像和它的名字,这里的指数:

<div ng-repeat="producto in productos">  
      <figure class="floating"> 
       <img ng-src="{{ image }}" alt="Macaque in the trees" class="rcorners3" style='width:100%;' border="0" alt="Null"> 
       <figcaption>{{ name }}</figcaption> 
      </figure> 
    </div> 

在顶部,我有:

<body ng-app="app"> 


<div class="main" ng-controller="app"> 

这是怎么MainController .js文件看起来像:

app.controller('app', ['$scope', function ($scope) { 
    $scope.productos = [{ 
      name : 'Management Guides', 
      image : url('managemant-guides.jpg') 
     }, { 
      name : 'Leaflets', 
      image : url('managemant-guides.jpg') 
     }, { 
      name : 'Production Charts', 
      image : url('managemant-guides.jpg') 
     }, { 
      name : 'Technical Guides', 
      image : url('managemant-guides.jpg') 
     }, { 
      name : 'Poultry News', 
      image : url('managemant-guides.jpg') 
     } 
    ]; 
}]); 

我tihnk我未能在NG-SRC点,不

回答

3

您应该使用:

ng-src="{{ producto.image }}" 
+0

谢谢你,我得到一个白色的页面aplying您的解决方案后,说URL没有定义,所以我修改了控制器的阵列也是如此。感谢您的帮助。 – xxxxxxxxxxxxx

2

你犯了一个错误。使用“PRODUCTO”为重点

<div ng-repeat="producto in productos">  
       <figure class="floating"> 
        <img ng-src="{{ producto.image }}" alt="Macaque in the trees" class="rcorners3" style='width:100%;' border="0" alt="Null"> 
        <figcaption>{{ producto.name }}"</figcaption> 
       </figure> 
     </div> 
+0

谢谢你,解决方案后,我得到一个白页,说URL没有定义,所以我修改了控制器中的数组。感谢您的帮助。 – xxxxxxxxxxxxx

+0

编辑,实际上ng-src =“{{producto.name}}是错误的,不需要ng-src用于.name,它仅适用于{{producto.name}} – xxxxxxxxxxxxx

+0

yup ..这是错误的。 – Ved