2015-07-21 59 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