2

EDIT: TIL that you don't need to add the url in the scope. Also, to be careful with the key, thanks.

I'm trying to show some images and its names in an HTML5 doc, here's the index:

    <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>

At the top I have:

    <body ng-app="app"> 


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

And this is how the MainController.js looks like:

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')
        }
    ];
}]);

I tihnk I'm failing at the ng-src point, not

2 Answers 2

4

You should be using:

 ng-src="{{ producto.image }}"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, after aplying your solution I was getting a white page, saying that the URL is not defined, so I modified the array in the controller as well. Thank you for your help.
2

You are making a mistake. Use 'producto' as key

<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>

2 Comments

Thank you, after aplying your solution I was getting a white page, saying that the URL is not defined, so I modified the array in the controller as well. Thank you for your help.
Edit, actually ng-src="{{ producto.name }} is wrong, no ng-src is needed for the .name, it works with just {{ producto.name}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.