![](/img/trans.png)
[英]How to skip ui-router's ui-view and redirect partial url without .html extension in AngularJS
[英]AngularJS UI-Router: Rendering parent partial with child partial
我正在為AngularJS使用UI-Router框架,以渲染嵌套的部分。 我在渲染父子項和子子項時遇到問題。 這是我的代碼:
window.app.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('class', {
url: '/classes/:classId',
templateUrl: '/views/class.html',
controller: 'ClassCtrl',
})
.state('class.questionList', {
url: '',
templateUrl: '/views/questionList.html',
})
}]);
在聲明子狀態時,我將url設置為空字符串,以便它可以與父字符串同時呈現。 但是,這不起作用,僅父視圖正在渲染。
將屬性“ abstract:true”添加到父狀態,以通知UI-Router該狀態只能通過激活子狀態來激活。 這將使URL / classes /:classId激活兩種狀態。
隱含子狀態意味着您要從現有狀態導航到該狀態,這應該更新與該狀態匹配的url。
從您的路線看來,您想要在class.html
的ui-view
中顯示某些class.html
,但不希望將狀態更改為child。 最好使用ng-include
,它將很好地達到目的
在您的class.html
,添加ui-view
使用ng-include
<ng-include src="'/views/questionList.html'"></ng-include>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.