【发布时间】:2015-09-08 02:17:16
【问题描述】:
我正在创建一个网络应用程序来帮助学生学习科学、历史和数学。当您第一次登陆该网站时,我有一个主页/登陆页面。当您单击开始时,我将路由到 /exam/instructions。我加载到ui-view="exam-detail" 中的每个步骤说明、数学和科学我们的模板。目前,当我通过科学导航往返指令时,整个ui-view 都会加载。理想情况下,我只需要一个用于分页的区域和一个用于主题的区域,并且只希望 ui-view="exam-detail" 使用正确的模板进行更新。
我根本没有使用过 UI-Router,我们将不胜感激。
index.html
<div ui-view></div>
state-exam>exam.html
<div class="state-exam">
<nav ui-view="exam-pagination"></nav>
<section ui-view="exam-detail"></section>
</div>
route.js
(function() {
'use strict';
angular
.module('studentPortal')
.config(routeConfig);
function routeConfig($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'app/main/main.html',
controller: 'MainController',
controllerAs: 'main'
})
.state('exam', {
url: '/exam/:step',
abstract: true,
templateUrl: 'app/state-exam/exam.html',
controller: 'ExamController',
controllerAs: 'examController',
})
.state('exam.instructions', {
url: '/instructions',
views: {
'exam-pagination':{
templateUrl: 'app/state-exam/exam-pagination.html'
},
'exam-detail' : {
templateUrl: 'app/state-exam/exam-instructions.html'
}
}
})
.state('exam.math', {
url: '/math',
views: {
'exam-pagination':{
templateUrl: 'app/state-exam/exam-pagination.html'
},
'exam-detail' : {
templateUrl: 'app/state-exam/exam-math.html'
}
}
});
$urlRouterProvider.otherwise('/');
}
})();
【问题讨论】:
-
您可以简单地做的是将导航创建为单独的指令并将其包含在 master.html 中,而不是将其作为 ui-view
-
@maddygoround,谢谢,是的,我想我想多了。这样可行。再次感谢。
标签: javascript jquery angularjs angular-ui-router