Javascript 无法使用angular ui路由器加载视图
我正在使用AngularUI路由器教程 当我想加载home.html页面时,它不起作用 我为每个页面定义了3个状态,并定义了它们的模板url,但导航根本不起作用Javascript 无法使用angular ui路由器加载视图,javascript,angularjs,Javascript,Angularjs,我正在使用AngularUI路由器教程 当我想加载home.html页面时,它不起作用 我为每个页面定义了3个状态,并定义了它们的模板url,但导航根本不起作用 http://localhost:8080/index.html#/home. 这是index.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>catalogue</title>
http://localhost:8080/index.html#/home.
这是index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>catalogue</title>
<link rel="stylesheet" type="text/css"
href="node_modules/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css"
href="css/myStyle.css" />
</head>
<body ng-app="MyApp" >
<div ui-view >
</div>
<script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
<script type="text/javascript" src="node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>
home.html:
<div>
<h1>home</h1>
</div>
家
设置默认URL状态
var app=angular.module("MyApp",['ui.router']);
app.config(function($stateProvider,$urlRouterProvider) {
$stateProvider.state('home',{
url:'/home',
templateUrl: 'views/home.html',
controller: 'HomeController'
});
$stateProvider.state('chercher',{
url:'/chercher',
templateUrl: 'views/chercher.html',
controller: 'MyController'
});
$stateProvider.state('newProduct',{
url:'/newProduct',
templateUrl: 'views/newProduct.html',
controller: 'NewProductController'
});
// add this code
$urlRouterProvider.otherwise('/home');
});
app.controller('HomeController', function() {
});
app.controller('NewProduitController', function() {
});
在浏览器中打开此链接我解决了问题
我使用了ui sref,而不是直接在URL浏览器中编写
<button ui-sref="home" >Home</button>
主页
它会抛出什么错误?没有。但是浏览器没有显示任何内容
<button ui-sref="home" >Home</button>