我在我的一个应用程序中使用 ngView 的 angularJS。但它在我的本地系统上运行良好,但在我的服务器上无法运行。有各种视图,如 HomeScreen、DeviceRegistration 等。当我单击 HomeScreen 时,其相关视图应显示在具有属性 ng-view 的 div 中。
下面是html的代码:
<body ng-controller="TrackingSystemCtrl">
<div class="mainDiv">
Choose:
<a href="HomeScreen">HomeScreen</a>
<a href="DeviceRegistration">DeviceRegistration</a> |
<a href="RegistrationInfo">RegistrationInfo</a> |
<a href="TrackerScreen">TrackerScreen</a>
<a href="AvailableDeviceList">AvailableDeviceList</a> |
<a href="FriendInfo">FriendInfo</a>
<a href="AvailableDeviceList">AvailableDeviceList</a> |
<div ng-view></div>
</div>
</body>
下面是控制器的代码:
angular.module('trackingSystem', [], function($routeProvider, $locationProvider) {
$routeProvider.when('/AvailableDeviceList', {
templateUrl: 'views/AvailableDeviceList.html',
controller: AvailableDeviceListCtrl
});
$routeProvider.when('/DeviceRegistration', {
templateUrl: 'views/DeviceRegistration.html',
controller: DeviceRegistrationCtrl
});
$routeProvider.when('/FriendInfo', {
templateUrl: 'http://webesperto.com/trackingsystemapp/views/FriendInfo.html',
controller: FriendInfoCtrl
});
$routeProvider.when('/HomeScreen', {
templateUrl: 'http://webesperto.com/trackingsystemapp/views/HomeScreen.html',
controller: HomeScreenCtrl
});
$routeProvider.when('/RegistrationInfo', {
templateUrl: 'http://webesperto.com/trackingsystemapp/views/RegistrationInfo.html',
controller: RegistrationInfoCtrl
});
$routeProvider.when('/TrackerScreen', {
templateUrl: 'views/TrackerScreen.html',
controller: TrackerScreenCtrl
});
$locationProvider.html5Mode(true);
});
function TrackingSystemCtrl($scope, $route, $routeParams, $location)
{
$scope.$route = $route;
$scope.$location = $location;
$scope.$routeParams = $routeParams;
$scope.isRegistered = false;
$scope.$on('$viewContentLoaded', function (event) {
console.log("view changed " + angular.toJson(event));
});
}