【问题标题】:AngularJS Controller is not working with ngRoute in IntelliJ (Web server issue?)AngularJS 控制器无法在 IntelliJ 中使用 ngRoute(Web 服务器问题?)
【发布时间】:2016-07-13 10:36:05
【问题描述】:

我正在使用 ngRoute 制作一个基本的应用程序。路由工作正常,但我的控制器内的范围元素没有显示在 html 中。

<p>{{ message }}</p>    <!-- Nothing shows -->
<p>{{ message }}X</p>   <!-- 'X' shows -->

主 html 中引用了 Angular、Route、App 和注册脚本。

<body>
  <div class="page">
    <main class="cf" ng-view></main>
  </div>
</body>

app.js

var myApp = angular.module('myApp', ['ngRoute']);

myApp.config(['$routeProvider', function($routeProvider) {

    $routeProvider
        .when('/login', {
            templateUrl: 'views/login.html',
            contoller: 'RegistrationController'
        })
        .when('/register', {
            templateUrl: 'views/register.html',
            contoller: 'RegistrationController'
        })
        .otherwise({
            redirectTo: '/login'
        });

}]);

registration.js

myApp.controller('RegistrationController', ['$scope', function ($scope) {

    $scope.message = "Welcome to my App!";

}]);

登录.html

<section class="card login">
  <form name="myform"
    novalidate>

    <div class="textintro">
      <h1>Hi there!</h1>
      <p>Log-in to access the awesomeness!</p>
      <p>{{ message }}</p>
    </div>

    <fieldset>
      <input type="email" name="email" placeholder="Email">
      <input type="password" name="password" placeholder="Password">
    </fieldset>

    <button type="submit" class="btn">Login</button>
    <p>or <a href="#/register">register</a></p>
  </form>
</section>

【问题讨论】:

  • 一切对我来说都是正确的。如果你在你的$scope.message = ... 行上方抛出一个console.log("RegistrationController");,它会显示在控制台中吗?
  • @Lex 没有输出。不知何故,控制器没有连接到视图。

标签: html angularjs intellij-idea controller ngroute


【解决方案1】:

这是一个错字:

contoller: 'RegistrationController'

应该是:

controller: 'RegistrationController'

【讨论】:

  • 呃!都是些小事!谢谢莱克斯!
猜你喜欢
  • 2015-08-30
  • 2017-08-31
  • 2016-08-25
  • 2019-07-05
  • 2018-09-29
  • 2017-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多