[英]Why Won't My Angular Template/Controller Load in ngView?
I'm having trouble getting my routes configured in Angular (1.3.14). 我在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. 我已经看了很多类似的例子这一个和这一个还有这里的几个其他的答案在SO,而据我所知,这是设置正确,但是当我加载它在浏览器中,没有负载的屏幕。 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). 没有控制台错误,并且通过注释掉$ locationProvider行(已将哈希添加回URL)验证了Angular正在运行。
Code is currently: 代码当前为:
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");
});
<div>
HELLO
</div>
<!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. 我尝试将ng-app标签添加到正文中的div,尝试使用ng-view指令,但是这些都不会改变结果。 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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.