[英]Simple AngularJS routing not working
Home and About page have simple heading content which is not showing when running the page. “主页”和“ 关于”页面具有简单的标题内容,在运行页面时未显示。 Instead it is showing:
而是显示:
Error: $injector:modulerr
错误:$ injector:modulerr
Module Error".模块错误“。
How do I fix this? 我该如何解决?
var app = angular.module('myApp', ['ngRoute']); app.config(function ($routeProvider) { $routeProvider. .when('/', { templateUrl : 'partial/home.html', }) .when('/about', { templateUrl: 'partial/about.html', }) otherwise({ redirectTo: '/'}) });
<div class="container"> <div> <nav> <a href="#/">Home</a> <a href="#/about">About</a> </nav> </div> </div>
Although I haven't run your code, I can see a syntax error. 虽然我没有运行你的代码,但我可以看到语法错误。
EDIT: Actually you have two syntax errors, rather than missing out a '.', you've added two after $routeProvider. 编辑:实际上你有两个语法错误,而不是错过了'。',你在$ routeProvider之后添加了两个。
app.config(function ($routeProvider) {
$routeProvider. //Two '.'s
.when('/', {
templateUrl : 'partial/home.html',
})
.when('/about', {
templateUrl: 'partial/about.html',
})
//No '.' here
otherwise({ redirectTo: '/'})
});
So replace the above with the '.', so the function chaining doesn't break. 所以用'。'代替上面的内容,这样函数链就不会破坏。
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'partial/home.html',
})
.when('/about', {
templateUrl: 'partial/about.html',
})
.otherwise({ redirectTo: '/'})
});
此外,您应该使用$urlRouterProvider
$urlRouterProvider.otherwise('/');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.