0

I have an AngularJS 1.0.7 webapp.

I had this code:

<div class="inspiration-wrapper">                       
                        <a href="/{{locationService.getLangKey()}}/{{'URL_BOAT_RENTALS_IBIZA' | translate}}" 
                           class="inspiration-link">                            
                            <img ng-src="//{{S3_BUCKET}}.{{PHOTO_SERVER_URL}}/img/inspiration/ibiza/inspiration-ibiza-1.jpg"
                                 class="inspiration-image"
                                 alt="{{'ALT_INSPIRATION' | translate}} {{'INSPIRATION_IBIZA' | translate}}"
                                 title="{{'TITLE_INSPIRATION_IBIZA' | translate}}">
                            <div class="inspiration-title" style="left: 270px">
                                {{'INSPIRATION_IBIZA' | translate}}
                            </div>
                        </a>                        
                    </div>

This is working great! However, we are improving our user experience and some parts are being redesign. Our designer suggest this change:

<div class="inspiration-wrapper" style="background-image:url('//{{S3_BUCKET}}.{{PHOTO_SERVER_URL}}/img/inspiration/ibiza/inspiration-ibiza-1.jpg')">                        
                        <a href="/{{locationService.getLangKey()}}/{{'URL_BOAT_RENTALS_IBIZA' | translate}}" 
                           class="inspiration-link" alt="{{'ALT_INSPIRATION' | translate}} {{'INSPIRATION_IBIZA' | translate}}"
                   title="{{'TITLE_INSPIRATION_IBIZA' | translate}}">
                            <div class="inspiration-title">
                                {{'INSPIRATION_IBIZA' | translate}}
                            </div>
                        </a>                        
                    </div>

This means, the image is not loaded as an img tag with ng-src attribute anymore, and it´s loading it in a background-img css property. This is a better approach from the design point of view.

Of course, when this is done, I get this error: GET http://%7B%7Bs3_bucket%7D%7D.%7B%7Bphoto_server_url%7D%7D/img/inspiration/ibiza/inspiration-ibiza-1.jpg net::ERR_NAME_NOT_RESOLVED

Is there any way to achieve what we are trying to do and avoid this error?

1 Answer 1

2

Yes use ng-style:

<div class="inspiration-wrapper" ng-style="{'background-image': 'url(//' + S3_BUCKET + '.' + PHOTO_SERVER_URL + '/img/inspiration/ibiza/inspiration-ibiza-1.jpg)'}">
Sign up to request clarification or add additional context in comments.

4 Comments

The error has disappear. However the images are not loading. I just added "ng-" before style. Before that the images were displaying.
Check your final url is good, inspect element and look at what url it's asking
Url looks good. ng-style="background-image:url('//yanpy.dev.s3.amazonaws.com/img/inspiration/ibiza/inspiration-ibiza-1.jpg')". If I just inspect the element and remove ng- the image is automatically displayed.
Please try this <div class="inspiration-wrapper" ng-style="{'background-image': 'url(//' + S3_BUCKET + '.' + PHOTO_SERVER_URL + '/img/inspiration/ibiza/inspiration-ibiza-1.jpg)'}">

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.