我正在关注AngularJS的教程 - "Building a website with AngularJS"
我使用的路线与教程几乎相同:
// JavaScript Document
angular.module('quest', []).
config(function($routeProvider) {
$routeProvider.
when('/about', {template:'partials/about.html'}).
when('/start', {template:'partials/start.html'}).
otherwise({redirectTo:'/home', template:'partials/home.html'});
});
问题是:它只显示资源的路径,而不是资源的内容,因此它不显示html内容,而是显示:
PARTIALS/ABOUT.HTML
我不确定我做错了什么,但它确实有效,如果我转到#/ about网址,它会显示“PARTIALS / ABOUT.HTML”如果我将网址更改为index.html#/ start it shows “谐音/的start.html”
页面的HTML:
<!DOCTYPE html>
<html lang="en" ng-app="quest">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title></title>
</head>
<body ng-controller="MainController">
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/quest.js"></script>
<div ng-view></div>
</body>
</html>
答案 0 :(得分:11)
使用templateUrl
代替template