我正在尝试使用UI-Router实现AngularJS路由。我有index.html文件,它试图使用app.js作为javascript加载部分productListView.html,但我看到错误:意外请求:在我的控制台中获取productListView.html。任何帮助将不胜感激。
的index.html:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Acme Product Management</title>
<!--Style Sheets-->
<link rel="stylesheet" type="text/css" href="styles/app.css">
<link rel="stylesheet" type="text/css" href="styles/bootstrap.css">
</head>
<body ng-app="productManagement">
<div class="container">
<div ui-view></div>
</div>
<!--Library Scripts-->
<script src="js/angular.min.js"></script>
<script src="js/angular-mocks.js"></script>
<script src="js/angular-resource.min.js"></script>
<script src="js/angular-ui-router.min.js"></script>
<!--Application Script-->
<script src="app.js"></script>
<!--Services-->
<script src="common/services/common-services.js"></script>
<script src="common/services/productResource.js"></script>
<script src="common/services/productResourceMock.js"></script>
<!--Product Controllers-->
<script src="products/productListCtrl.js"></script>
</body>
</html>
app.js:
(function(){
'use strict';
angular.module('productManagement',['common-services',
'productResourceMock',
'ui.router'])
.config(['$stateProvider',
'$urlRouterProvider',
function($stateProvider,
$urlRouterProvider){
$urlRouterProvider.otherwise('/products');
$stateProvider
.state('productList', {
url: '/products',
templateUrl: 'products/productListView.html',
controller: 'ProductListCtrl'
});
}]
);
})();
答案 0 :(得分:8)
我认为,您必须更改$httpBackend.whenGET(/app/).passThrough();
文件
productResourceMock.js
答案 1 :(得分:0)
您错误地排除了用于在HTML文件中进行测试的Javascript文件。您看到的错误来自&#34; mock&#34;单元测试中使用的HTTPBackend版本。
您应该从HTML中删除这些行:
<script src="js/angular-mocks.js"></script>
<script src="common/services/productResourceMock.js"></script>