0

Been bashing my head against this for a couple of hours now and I'm out of ideas. I'm brand new to angular and trying to build a very basic application just to get a handle on it.

Relevant parts of the application are as follows:

main.html

<!doctype html>
<html>
    <head>
        <link href="css/main.css" rel="stylesheet" type="text/css"></link>
        <link href="https://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet">
    </head>
    <body ng-app="weatherApp">
        <div class="main">
            <div class="navbar">
                <div class="vCentered">
                    <img src="assets/logo.png" id="logo">
                </div>
            </div>
            <div ng-view>
            </div>
        </div>
    </body>

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>

    <script src="js/app.js"></script>


</html>

app.js

var app = angular.module("weatherApp",  ["ngRoute"]);

app.config(function($routeProvider)
          {
  $routeProvider
  .when('/', {
    templateUrl: "home.html";
  })
  .otherwise({
    redirectTo: '/'
  });
});

home.html

<h1>Hello.</h1>

Very basic. The issue is that, no matter what, I can't get the contents of home.html to show up when main.html is loaded. Note that the content does display when I use the following code in app.js:

  $routeProvider
  .when('/', {
    template: "Hello.";
  })

So it appears to be some kind of problem with templateUrl actually finding home.html.

I have put home.html everywhere. It's littered throughout my PC now on the off chance that templateUrl is hunting for it there but so far no luck in having anything load.

I have tried turning on Internet Information Services on my machine and putting the project into the inetpub/wwwroot folder but that hasn't helped. (Running Windows 10)

Any ideas on what I'm doing wrong would be very much appreciated.

7
  • Just to clarify both the index.html and home.html are in the same place? if you wanna skip the hassle go with <script type="text/ng-template" id="home.html"> <h1>Blog</h1> </script> Commented Aug 28, 2017 at 18:09
  • main.html and home.html are in the same place. I'd prefer to work out how to fix the problem for future use :) Commented Aug 28, 2017 at 18:10
  • I am assuming index.html is in the root of the project so what you need to do is place app.js in the same path as index.html and change <script src="app.js"></script> Commented Aug 28, 2017 at 18:14
  • Okay, I've tried that and it seems to have worked! Is there any way I can move app.js back to the js folder without breaking the links? Commented Aug 28, 2017 at 18:31
  • 1
    you need to set relative path from the app.js to the home.html so that will be templateUrl: "../home.html"(look one folder behind for index.html) can you try this? with app.js inside the JS folder also <script src="js/app.js"></script> change this in index.html Commented Aug 28, 2017 at 18:34

1 Answer 1

1

Template url had to be set to

templateUrl: "../project%20name/home.html"

Also ensure that you access the project through localhost/main.html in the browser as that tripped me up at another point.

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

Comments

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.