我正在努力学习角度。有人能告诉我为什么home.html没有显示在我的角度应用程序上?我已经包含所有必需的角度文件。启动应用程序时没有错误,只是一个空白屏幕。 jquery,bootstrap和fontawesome以前都在工作,所以没有问题。我可以添加一个调试器语句,看看app.js是否被调用,但是主页视图没有显示。
我的解决方案中的文件夹结构:
根:
/index.html
/home.html
App文件夹:
应用程序/角route.js
应用程序/ app.js
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Learning Angular</title>
<link href="libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="libs/fontawesome/css/font-awesome.min.css" rel="stylesheet" />
<link href="css/main.css" rel="stylesheet" />
<script src="libs/angular/angular.min.js"></script>
<script src="app/angular-route.js"></script>
<script src="app/app.js"></script>
</head>
<body ng-app="myApp">
<div class="container">
<div ng-view></div>
</div> <!-- /container -->
</body>
<script src="libs/jquery/jquery-2.1.4.min.js"></script>
<script src="libs/bootstrap/js/bootstrap.min.js"></script>
</html>
home.html的
<p>
Welcome to Home {{user.firstName}}
</p>
<div class="row">
<div class="col-md-6">
<form class="registrationForm">
<h2 class="form-signin-heading faArrowIcon">Please sign in</h2>
<label for="inputEmail">Email address</label>
<input type="email" id="inputEmail" class="form-control validateIt" placeholder="Email address" required autofocus>
<label for="inputPassword">Password</label>
<input type="password" id="inputPassword" class="form-control validateIt" placeholder="Password" required>
<div style="padding: 0; margin: 0;" class="col-md-3 pull-right">
<button id="submitButton" class="btn btn-lg btn-primary btn-block" type="submit" disabled>Sign in</button>
</div>
</form>
</div>
</div>
app.js
var sampleApp = angular.module('myApp', ['ngRoute']);
sampleApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/AddNewOrder', {
templateUrl: 'templates/add_order.html',
controller: 'AddOrderController'
}).
when('/ShowOrders', {
templateUrl: 'templates/show_orders.html',
controller: 'ShowOrdersController'
}).
otherwise({
redirectTo: '/home.html'
});
}]);
sampleApp.controller('AddOrderController', function($scope) {
$scope.message = 'This is Add new order screen';
});
sampleApp.controller('ShowOrdersController', function($scope) {
$scope.message = 'This is Show orders screen';
});
答案 0 :(得分:2)
您需要为家庭指定路线并将其设置为主要路线。
这是一个例子:
app.config(function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'home.html',
}).
when('/route2', {
templateUrl: 'route2.html',
}).
otherwise({
redirectTo: '/'
});
});
的index.html
<body ng-controller="MainCtrl">
<div>
<a href="#/home">home</a>
<a href="#/route2">route2</a>
</div>
<div ng-view></div>
</body>
和工作plnkr