我正在尝试使用 ngRoute 在 agularjs 1.6 中创建单页应用程序。我的代码如下。
角码
let mainAngularModule = angular.module("acc-management", ['ngMaterial','ngRoute']);
mainAngularModule.config(routeConfig);
routeConfig.$inject = ['$routeProvider'];
function routeConfig($routeProvider, $locationProvider) {
$routeProvider
.when('/Personaldata', {
templateUrl: 'PersonalPreference.html',
controller: 'PersondataController as personController'
})
.when('/UserData', {
templateUrl: 'UserDefinedElement.html',
controller: 'accountController as accController'
})
}
class AccountController {
static $inject = ["$scope"];
constructor(private $scope) {
debugger;
}
}
mainAngularModule.controller("accountController", AccountController);
mainAngularModule.controller("PersondataController", PersonalPreferencesController);
class PersondataController {
public scope: Object = {
title: "Personal Preferences"
}
}
class UserData {
}
HTML
<div layout="row" layout-xs="column">
<div flex="18">
<md-subheader class="md-no-sticky">User Preferences</md-subheader>
<md-list-item href="#/PersonalPreferences">
<span>Personal Preferences</span>
</md-list-item>
<md-list href="#/UserData">
<span>User Data</span>
</md-list>
</md-sidenav>
</div>
<div flex>
<md-content layout-padding>
<div ng-view></div>
</md-content>
</div>
</div>
我的代码在路由中运行良好。在用户数据中,我有子菜单的地址,资格。我不知道我应该如何为它编写角度路由代码(嵌套路由)。下面是我的 html 代码。
HTML
<div layout="row" layout-xs="column">
<div flex="18">
<md-list-item href="#/">
<span>Address</span>
</md-list-item>
<md-list href="#/">
<span>Qualifications</span>
</md-list>
</div>
</div>