1

I can't for the life of me figure out why my jpg image isn't rendering on my local computer. I'm writing a simple web app using AngularJS.

I have the images in an "img" folder within the same directory as the home.html file.

Could it be something wrong with the picture? I'm able to open it and it looks renders fine. I don't see any errors in the console either, just a broken image. Maybe it's the way I'm using bootstrap or angular? I'm relatively new to both.

home.html code:

<!DOCTYPE html>
<html data-ng-app="MainApp">
    <head>
        <title>FedCup 5k</title>
        <!--angular uses this base element which path to use when it gets any front end resource- this is the root b/c of "/"-->
        <base href='/'>
        <link rel="stylesheet" type="text/css" href="src/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="lib/bootstrap/dist/css/bootstrap.min.css">
    </head>
    <body>
        <div class='container'>
            <div class='page-header'>
                <h1>FedCup 5k</h1>
                <div class="row">
                    <div class="col-sm-12">
                        <img src="img/test.jpg"/>
                    </div>
                </div>
            </div>
                    <!--the place holder to render our view dependent on the route-->
            <div class="row">
                <div class="col-sm-12" data-ng-view>
                </div>
            </div>
        </div>

        <script type='text/javascript' src="lib/jquery/dist/jquery.min.js"></script>
        <script type="text/css" src="lib/bootstrap/dist/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="lib/angular/angular.min.js"></script>
        <script type="text/javascript" src="lib/angular-route/angular-route.min.js"></script>
        <script type="text/javascript" src="lib/angular-resource/angular-resource.min.js"></script>
        <script type="text/javascript" src="src/app.js"></script>
        <script type="text/javascript" src="src/controller.js"></script>
        <script type="text/javascript" src="src/factories.js"></script>
        <script type="text/javascript" src="src/filter.js"></script>

    </body>
</html>

Thanks so much for your help! I'm hoping it's just something stupid I'm overlooking because I've been staring at this for so long and it looks like it should be easy.

5
  • home.html located in img directory ? Commented Jun 11, 2015 at 13:17
  • do you have any errors in the console? Commented Jun 11, 2015 at 13:18
  • no, home.html is one level up. Commented Jun 11, 2015 at 14:58
  • I have a Public folder with home.html in it. I have the img folder within the Public folder. Commented Jun 11, 2015 at 14:58
  • no errors on the console. Commented Jun 11, 2015 at 15:37

2 Answers 2

2

You have to access the folder in your local directory where the images are placed through slashes.i.e if you have folder img then you have to access it in html via <img src="/img/test.jpg"/>

Sign up to request clarification or add additional context in comments.

5 Comments

I just tried this and it didn't work. the folder "img" is not in the root. It's one level up in a "public" folder. This is the folder structure: "public/img/test.jpg" and then the html file is located at "public/home.html". Does that make sense? I'm using angular-routes to point to the home.html file.
If you show the route of the broken image, it looks like what ?
It's weird. What is the software you use ? EasyPhp ? Normally, this works . For example in easyphp the localweb is "www" so you can have home.html and the folder img in there. If you remove the <base href='/'> and add the "/" before all the link, does it works ?
Thank you, Martel! That worked! It was the base reference that was throwing this off. I changed it to <base href=''>. I guess with angular 1.3, if you configure your location provider to have html5Mode on, it's best practice to include a base reference. I found this article helpful (if you're curious): docs.angularjs.org/error/$location/nobase Thank goodness this is solved, I was going crazy over something that looked to be simple!
Just a heads up everyone, I found this was because I was not running it on my localhost:8080 port (or any port for that matter). Once I added and configured a server.js file and started a local server, the <base href="/"> worked perfectly!
0

Sometimes src not work with angular. Use data-ng-src instead.

2 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.
@ Mamoun Benghezal ok i'll next time i'll take care of that.

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.