gpt4 book ai didi

javascript - Uncaught Error : [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:modulerr]

转载 作者:太空宇宙 更新时间:2023-11-04 02:17:07 29 4
gpt4 key购买 nike

我使用环回作为后端,使用 postgresql 作为数据库。所以我尝试使用 lb-service/js。

如果我尝试在 login.js 中包含 lbServices (angular.module('myApp',['ngRoute' ,'lbServices']) .. 等)意味着会出现错误。

错误详细信息:

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:modulerr] Failed to instantiate module ngRoute due to: Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

索引.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Myapps</title>
<!-- Bootstrap -->
<link href="vendor/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
<script src="vendor/theme_files/js/jquery.min.js"></script>
<script src="vendor/angular/angular.js"></script>
<script src="vendor/angular-resource/angular-resource.js"></script>
<script src="vendor/angular-ui-router/release/angular-ui-router.js"></script>
<script src="js/services/lb-services.js"></script>
</head>
<body ng-app="myApp" class="nav-md " style="background:#F7F7F7;">
<div class="container body" ui-view></div>
<script src="vendor/bootstrap/dist/js/bootstrap.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/loginController.js"></script>
<script src="js/services/login.js"></script>

</body>
</html>

登录.html

<div id="wrapper">
<div id="login" class="animate form">
<section class="login_content">
<form ng-submit="login()">
<br>
<h1>Login</h1>
<div>
<input type="text" class="form-control" ng-model="loginForm.username" placeholder="Username" required="" />
</div>
<div>
<input type="password" class="form-control" ng-model="loginForm.password" placeholder="Password" required="" />
</div>
<div>

<button type="submit" class="btn btn-default submi" ng-disabled="disabled">
Log in
</button>

<a class="reset_pass" href="#">Lost your password?</a>
</div>
<div ng-show="error" class="alert alert-danger">
{{errorMessage}}
</div>
</form>
</section>
<!-- content -->
</div>

</div>

app.js

angular.module('myApp', ['lbServices', 'ui.router']).config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$stateProvider.state('todo', {
url : '',
templateUrl : 'views/login.html',
controller : 'loginController'
}).state('login', {
url : '/login',
templateUrl : 'views/login.html',
controller : 'loginController'
}).state('profile', {
url : '/profile',
templateUrl : 'views/profile.html',
controller : 'loginController'
});
$urlRouterProvider.otherwise('login');

}]);

登录 Controller .js

angular.module('myApp').controller('loginController', ['$scope', '$location', 'AuthService',
function($scope, $location, AuthService) {
$scope.login = function() {
// initial values
$scope.error = false;
$scope.disabled = true;
// call login from service
AuthService.login($scope.loginForm.username, $scope.loginForm.password)
// handle success
.then(function() {
$location.path('/index');
$scope.disabled = false;
$scope.loginForm = {};
})
// handle error
.catch(function() {

$scope.error = true;
$scope.errorMessage = "Invalid username and/or password";
$scope.disabled = false;
$scope.loginForm = {};
});

};

}]);

服务/login.js

angular.module('myApp',['ngRoute' ,'lbServices']).factory('AuthService', ['$q', '$timeout', '$http',
function($q, $timeout, $http) {

// create user variable
var user = null;

// return available functions for use in controllers
return ( {
isLoggedIn : isLoggedIn,
getUserStatus : getUserStatus,
login : login,
logout : logout,
register : register
});

function isLoggedIn() {
if (user) {
return true;
} else {
return false;
}
}

function getUserStatus() {
return user;
}

function login(username, password) {

// create a new instance of deferred
var deferred = $q.defer();
// send a post request to the server
$http.post('/api/login', {
username : username,
password : password
})
// handle success
.success(function(data, status) {
if (data.status === 200 && data.status) {
user = true;
deferred.resolve();
} else {
user = false;
deferred.reject();
}
})
// handle error
.error(function(data) {
user = false;
deferred.reject();
});

// return promise object
return deferred.promise;

}

}]);

最佳答案

将login.js编辑为

angular.module('myApp',['ui.router' ,'lbServices'])

关于javascript - Uncaught Error : [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:modulerr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35216106/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com