1

I'm trying to create a login/signup site in order to learn how to separate controllers and partial views, but I'm not sure why my 'LoginController' isn't being injected. Feel free to provide any other feedback.

app.js

angular.module('Registration', ['ngRoute'])
.config(['$routeProvider', ($routeProvider) => {
  $routeProvider
    .when('/login', {
      templateUrl: 'app/login/login.html',
      controller: 'LoginController'
    })
    .otherwise({ redirectTo: '/login' });
}]);

LoginController.js

angular.module('Registration')
.controller('LoginController', ['$scope', ($scope) => {
  $scope.message = 'Does this work?';
}]);

login.html

<div class="col-md-offset-3 col-md-6">
{{ message }}
</div>

index.html

<!doctype html>
<html ng-app="Registration">
<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>Sup?</title>
  <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="assets/css/styles.css">
</head>
<body>
  <div class="container">
    <div class="row">
      <div ng-view></div>
    </div>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="assets/js/bootstrap.min.js"></script>
  <script src="assets/js/angular.min.js"></script>
  <script src="assets/js/angular-route.min.js"></script>
  <script src="app/app.js"></script>
  <script src="app/login/LoginController.js"></script>
</body>
</html>

server.js

var express = require('express');
var app = express();

app.use(express.static('./public'));

app.listen(3000, () => {
  console.log('Listening on port 3000.');
});

Directory Structure

2
  • What do you see in console when you move to /login? Commented Jan 29, 2017 at 21:01
  • TypeError: Function.prototype.bind.apply(...) is not a constructor Commented Jan 30, 2017 at 3:33

2 Answers 2

1

Turns out you can't use an arrow function in the controller! Totally didn't mean to answer my own question.

Found the answer here: https://github.com/angular/angular.js/issues/14814

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

Comments

0

Just try to reach to your login route like http://localhost:8080/#/login

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.