这是一个小时我试图理解为什么我没有调用我在AngularJS项目的控制器中定义的函数。
app.js
angular.module('SupplierPortal', ['ngRoute', 'ngResource']);
userLoginController.js
angular.module('SupplierPortal').controller('UserLoginController', function($scope, $location) {
$scope.text = "Hi";
$scope.login = function() {
console.log('It doesn't show this');
$location.path(/admin);
}
});
的login.html
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<div class="account-wall">
<img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=120"
alt="">
<form class="form-signin">
<input type="text" class="form-control" placeholder="Username" required autofocus>
<input type="password" class="form-control" placeholder="Password" required>
<input class="btn btn-lg btn-primary btn-block" type="submit" ng-click="login()" value="Login">
</form>
</div>
</div>
</div>
routes.js
angular.module('SupplierPortal').config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "assets/templates/users/login.html",
controller: "UserLoginController"
})
.when("/admin/", {
templateUrl: "assets/templates/users/index_admin.html"
})
.otherwise({
redirectTo:'/'
});
});
的index.html
<!DOCTYPE html>
<html ng-app="SupplierPortal">
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="assets/styles/style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
</head>
<body>
<div ng-view class="container"></div>
<!-- SCRIPTS -->
<!-- Vendor -->
<script src="assets/javascript/vendor/angular.min.js"></script>
<script src="assets/javascript/vendor/angular-route.min.js"></script>
<script src="assets/javascript/vendor/angular-resource.min.js"></script>
<script src="assets/javascript/vendor/jquery-3.2.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- App -->
<script src="assets/javascript/app.js"></script>
<script src="assets/javascript/routes.js"></script>
<!-- Controllers -->
<script src="assets/javascript/controllers/users/userLoginController.js"></script>
<!-- Services -->
<script src="assets/javascript/services/user.js"></script>
它不会在控制台中显示文本,当然也不会显示在/ admin / path中。
感谢大家会尽力帮助我!
答案 0 :(得分:0)
修正以下行:
console.log('It doesn't show this');
在句子中间用“'”关闭字符串,因为你使用了“doens't”。使用“或不要使用”“doens't”字样