[英]Configure routes angular for menu
Confused with routes configuration in angular js. 与angular js中的路由配置混淆。 I want to learn how to configure this and don't import all the dependencies for each html file.
我想学习如何配置它,并且不导入每个html文件的所有依赖项。
This is what I do not want to have foreach file: 这是我不想拥有的foreach文件:
<script src="../../resources/jquery/jquery.min.js"></script>
<link rel="stylesheet" href="../../resources/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="../../resources/toastr/toastr.min.css" />
<script src="../../resources/angular/angular.min.js"></script>
<script src="../../resources/bootstrap/js/bootstrap.min.js"></script>
<script src="../../resources/toastr/toastr.min.js"></script>
<script src="../services/book.service.js"></script>
<script src="controllers/book.controller.js"></script>
1 - My appConfig.js with routes: 1-我的appConfig.js具有路线:
var app = angular.module("library.crud", ["ngRoute"]);
app.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'app/views/home.html',
controller: 'homeController',
controllerAs: 'vm'
})
.when('/book', {
templateUrl: 'app/views/book.html',
controller: 'bookController',
controllerAs: 'vm'
})
.when('/books', {
templateUrl: 'app/views/books.html',
controller: 'booksController',
controllerAs: 'vm'
})
.otherwise({
redirectTo: '/'
})
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
How do I use the appConfig file ? 如何使用appConfig文件?
My index menu: 我的索引菜单:
<html ng-app="library.crud">
<script src="appConfig.js"> </script>
<body ng-app="library.crud">
<a href="#/books">books</a>
<a href="#/book">book</a>
<div ng-view></div>
</body>
</html>
My index file is not working and show the message: "injector moduler etc..." 我的索引文件不起作用,并显示以下消息:“ injector moduler etc ...”
This was supposed to be a comment, but I'd need 50 points of reputation. 这本来应该是评论,但我需要50分的声誉。
You need to add the angular-route.js
file to your page. 您需要将
angular-route.js
文件添加到页面。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
Be careful with the AngularJS version you are using, the above is just an example. 请小心使用的AngularJS版本,以上仅为示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.