0

it's an hour I'm trying to understand why a function I defined inside a controller of an AngularJS project is not being called.

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>

It does not show the text in the console, and of course it does not go to /admin/ path.

Thanks to everyone will try to help me!

2
  • Sorry for the message in the console.log(), I wrote it only to show you the point, it's not the real message and so there is not the problem of the " ' " that closes the string to log in the console. Commented Apr 7, 2017 at 21:03
  • Any errors in console?, also what about the quotes in $location.path("/admin")? Commented Apr 7, 2017 at 21:08

1 Answer 1

0

fix the following line:

console.log('It doesn't show this');

the string is being closed with "'" in the middle of the sentence, because you used "doens't". either use " or dont use ' on the "doens't" word

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.