简体   繁体   中英

Why Won't My Angular Template/Controller Load in ngView?

I'm having trouble getting my routes configured in Angular (1.3.14). I've looked at plenty of examples like this one and this one as well as a few other answers here on SO, and as far as I can tell this is setup correctly, but when I load it in a browser, nothing loads to the screen. There are no console errors, and I've verified that Angular is running by commenting out the $locationProvider line (which adds the hash back to the url).

Code is currently:

app.js

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

app.config([
  '$routeProvider',
  '$locationProvider',
  function($routeProvider, $locationProvider) {

    $routeProvider.
      when('/', {
        templateURL: 'templates/home.html',
        controller: 'HomeController'
      }).
      otherwise({
        redirectTo: '/'
      });

    $locationProvider.html5Mode(true);

}]);
app.controller('HomeController', function($scope) {
  console.log("hi");
});

home.html

<div>
   HELLO
</div>

index.html

<!DOCTYPE html>
<html ng-app="app">
  <head>
    <base href="/">
    <link rel="stylesheet" type="text/css" href="stylesheets/style.min.css"/>
  </head>
  <body>

    <div ng-view></div>

    <script src="bower_components/angular/angular.min.js"></script>
    <script src="bower_components/angular-route/angular-route.js"></script>
    <script src="js/app.js"></script>
  </body>
</html>

I have also tried varying the way I declare the app. I tried adding the ng-app tag to a div in the body, I've tried using the ng-view directive, but neither of these things change the outcome. All the linked resources do load, I can view them all in dev tools. I can also navigate directly to the template file and it loads just fine. I think I'm missing something simple, but I cannot figure out what it is.

它应该是templateUrl ,而不是templateURL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM