如何获得使用 angularjs' ui-router 的多个视图示例
How to get this example of multiple views working with angularjs' ui-router
我在这里按照这些说明进行操作,但无法正常工作。
https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views
我通过将它们全部放入 index.html 并加载页面来验证我的 bootstrap 网格 div 是否正常工作。然后我“angularfied'它,页面没有呈现。
我在 javascript 控制台中没有看到任何错误。
首先,页面应该如下所示。在我从 index.html
拆分视图之前网页的实际屏幕截图
这是我添加 angular 并创建多个视图后的代码:
index.html
<html ng-app="WhosebugApp">
<head>
<meta charset="utf-8"/>
<title>Whosebug Question</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" type="text/css"/>
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="scripts/WhosebugApp.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div ui-view="WhosebugTopPane"/>
</div>
<!-- main panel-->
<div class="row">
<!-- Left pane-->
<div ui-view="WhosebugLeftPane"></div>
<!-- content pane-->
<div ui-view="WhosebugMainPane"></div>
</div>
</div>
</body>
</html>
js
'use strict';
angular.module('WhosebugApp', [
'ui.router'
])
.run(
['$rootScope', '$state', '$stateParams',
function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}
]
)
.config(
['$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {
/////////////////////////////
// Redirects and Otherwise //
/////////////////////////////
$urlRouterProvider
.otherwise('/');
//////////////////////////
// State Configurations //
//////////////////////////
// Use $stateProvider to configure your states.
$stateProvider
//////////
// Home //
//////////
.state("home", {
views: {
'WhosebugTopPane': {
templateUrl: 'so-views/Whosebug-top-pane.html'
},
'WhosebugLeftPane': {
templateUrl: 'so-views/Whosebug-left-pane.html'
},
'WhosebugMainPane': {
templateUrl: 'so-views/Whosebug-main-pane.html'
}
}
})
}
]
);
据我所知,您从未将 "home" 状态分配给 index.html URL。尝试在 "views"
之前设置 url: "/",
我在这里按照这些说明进行操作,但无法正常工作。 https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views
我通过将它们全部放入 index.html 并加载页面来验证我的 bootstrap 网格 div 是否正常工作。然后我“angularfied'它,页面没有呈现。
我在 javascript 控制台中没有看到任何错误。
首先,页面应该如下所示。在我从 index.html
拆分视图之前网页的实际屏幕截图这是我添加 angular 并创建多个视图后的代码:
index.html
<html ng-app="WhosebugApp">
<head>
<meta charset="utf-8"/>
<title>Whosebug Question</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" type="text/css"/>
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="scripts/WhosebugApp.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div ui-view="WhosebugTopPane"/>
</div>
<!-- main panel-->
<div class="row">
<!-- Left pane-->
<div ui-view="WhosebugLeftPane"></div>
<!-- content pane-->
<div ui-view="WhosebugMainPane"></div>
</div>
</div>
</body>
</html>
js
'use strict';
angular.module('WhosebugApp', [
'ui.router'
])
.run(
['$rootScope', '$state', '$stateParams',
function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}
]
)
.config(
['$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {
/////////////////////////////
// Redirects and Otherwise //
/////////////////////////////
$urlRouterProvider
.otherwise('/');
//////////////////////////
// State Configurations //
//////////////////////////
// Use $stateProvider to configure your states.
$stateProvider
//////////
// Home //
//////////
.state("home", {
views: {
'WhosebugTopPane': {
templateUrl: 'so-views/Whosebug-top-pane.html'
},
'WhosebugLeftPane': {
templateUrl: 'so-views/Whosebug-left-pane.html'
},
'WhosebugMainPane': {
templateUrl: 'so-views/Whosebug-main-pane.html'
}
}
})
}
]
);
据我所知,您从未将 "home" 状态分配给 index.html URL。尝试在 "views"
之前设置url: "/",