【发布时间】: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