【发布时间】:2016-07-03 00:00:18
【问题描述】:
我正在学习 angularJS。我正在尝试从教程视频中实现代码以使用 Route 在 html 页面上显示视图,但显然我被卡住了,尽管我做的与教程中显示的导师完全相同,但我有不知道为什么它不起作用,我已经在互联网上搜索但无效,请任何人指出我的错误。这是我的代码
Index.html
<html ng-app="App">
<head>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div ng-view></div>
<script src="js/angular.js"></script>
<script src="js/angularRoute.js"></script>
<script src="App/Myapp.js"></script>
<script src="App/CustomerController.js"></script>
</body>
</html>
App/MyApp.js
var App=angular.module('App',['ngRoute']);
App.config(function($routeprovider)
{
$routeprovider
.when('/',{
controller:'CustomerController',
templateUrl:'App/views/customers.html'
})
.otherwise({ redirectTo:'/'});
});
views/customers.html
<div class="heading">
<h1>Customers List</h1>
</div>
<div class="filterBox">
Filter:<input type="text" ng-model="CustomerFilter.name"/>
</div>
<table>
<th ng-click="sorter='CustomerID';reverse=!reverse">ID</th>
<th ng-click="sorter='name';reverse=!reverse">Name</th>
<th ng-click="sorter='city';reverse=!reverse">City</th>
<th ng-click="sorter='total_orders';reverse=!reverse">Total Orders</th>
<th ng-click="sorter='date';reverse=!reverse">Date of last Order</th>
<tr ng-repeat="cust in customers |filter:CustomerFilter|orderBy:sorter:reverse">
<td>{{ cust.CustomerID }}</td>
<td>{{ cust.name|uppercase }}</td>
<td>{{ cust.city |lowercase}}</td>
<td>{{ cust.total_orders|currency:'Rs' }}</td>
<td>{{ cust.date|date:'longDate' }}</td>
</tr>
</table>
<span> Total Customers:{{customers.length}}</span>
我有一个名为 CustomerController 的控制器,我没有在这里粘贴它,因为它太大而无法容纳。
【问题讨论】:
标签: javascript angularjs view routes ngroute