我正在尝试使用angularjs设置SPA。一切都像在工作示例中那样编写,但是我收到了2个“ [$ injector:unpr]”。有任何想法吗? ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀
我试图从.when()
中删除控制器,但无济于事。
controller-main.js:
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: '../data/main.html',
controller: 'controller-main'
})
.when('/analytics', {
templateUrl: '../data/analytics.html',
controller: 'controller-main'
})
.when('/settings', {
templateUrl: '../data/settings.html',
controller: 'controller-main'
})
.when('/exit', {
templateUrl: '../data/exit.html',
controller: 'controller-main'
})
.otherwise({redirectTo: '/'});
}]);
app.controller('controller-main', function($scope) {
// Must be recieved from server
$scope.page = {
company_name: 'samplecompanyname'
};
});
main.html:
<html ng-app="main-app">
<head ng-controller="controller-main">
<meta charset="UTF-8">
<title>{{ page.company_name }}</title>
...
</head>
<body>
...
<div id="current_page">
<div ng-view></div>
<div id="welcome_msg" ng-controller="controller-main">
Welcome, {{ page.company_name }}!
</div>
</div>
</div>
<script type="text/javascript" src="../js/loader_onlogin.js"></script>
<script type="text/javascript" src="../js/lib/anime.min.js"></script>
<script type="text/javascript" src="../js/lib/angular.min.js"></script>
<script type="text/javascript" src="../js/lib/angular-route.min.js"></script>
<script type="text/javascript" src="../js/controller-main.js"></script>
<script type="text/javascript" src="../js/controller-menu.js"></script>
<script type="text/javascript" src="../js/controller-page.js"></script>
</body>
</html>