我正在使用angular编写我的第一个应用程序。但得到 $ injector:modulerr 错误。我很困惑。谁能告诉我,我在这里做错了什么? 我已经使用ng-app =“starApp”启动了。然后在app.js中初始化我的模块
我的HTML代码 -
<!DOCTYPE html>
<html ng-app="starApp">
<head>
<meta charset="utf-8" />
<title>MY DEMO</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link href="app-content/app.css" rel="stylesheet" />
</head>
<body ng-controller = "LoginController">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
<script src="app.js"></script>
<script src="app-services/authentication.service.js"></script>
<script src="app-services/flash.service.js"></script>
<!-- Real user service that uses an api -->
<script src="app-services/user.service.js"></script>
<!-- Fake user service for demo that uses local storage -->
<script src="app-services/user.service.local-storage.js"></script>
<script src="home/home.controller.js"></script>
<script src="login/login.controller.js"></script>
<script src="register/register.controller.js"></script>
我的config.js -
'use strict';
var starApp = angular.module("starApp", ['ngRoute', 'ngCookies']);
// Main app config
starApp.config([
'$routeProvider',
'$sceDelegateProvider',
'$locationProvider',
'$httpProvider',
function($routeProvider, $sceDelegateProvider, $locationProvider,
$httpProvider, $compileProvider) {
$routeProvider.when('/', {
controller : 'HomeController',
templateUrl : 'home/home.view.html',
controllerAs : 'vm'
}).when('/login', {
controller : 'LoginController',
templateUrl : 'login/login.view.html',
controllerAs : 'vm'
})
.when('/register', {
controller : 'RegisterController',
templateUrl : 'register/register.view.html',
controllerAs : 'vm'
})
.otherwise({
redirectTo : '/login'
});
}]);
我的控制器,我试图为我的登录页面添加业务逻辑 -
(function() {
'use strict';
angular.module('starApp').controller('LoginController', LoginController);
LoginController.$inject = ['$location', 'AuthenticationService',
'FlashService'];
function LoginController($location, AuthenticationService, FlashService) {
var vm = this;
vm.login = login;
(function initController() {
// reset login status
AuthenticationService.ClearCredentials();
})();
function login() {
vm.dataLoading = true;
AuthenticationService.Login(vm.username, vm.password, function(
response) {
if (response.success) {
AuthenticationService.SetCredentials(vm.username,
vm.password);
$location.path('/');
} else {
FlashService.Error(response.message);
vm.dataLoading = false;
}
});
};
}
})();
答案 0 :(得分:0)
你是否在你的html中包含了config.js.
答案 1 :(得分:0)
.config
中的注射参数似乎不匹配。函数中有4个字符串但有5个参数。如果您未在配置中使用$compileProvider
,请将其作为参数删除,或者将其添加到字符串