AngularJS控制器不会加载到partial

时间:2017-01-29 20:34:26

标签: angularjs controller config

我正在尝试创建一个登录/注册站点,以便了解如何分离控制器和部分视图,但我不确定为什么我的'LoginController'没有被注入。随意提供任何其他反馈。

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 个答案:

答案 0 :(得分:1)

事实证明,您无法在控制器中使用箭头功能!完全没有意思回答我自己的问题。

在这里找到答案:https://github.com/angular/angular.js/issues/14814

答案 1 :(得分:0)

尝试访问您的登录路线,例如http://localhost:8080/#/login