Angular ui 路由器 - 模态内的嵌套视图
Angular ui router - nested view inside modal
我想将步骤向导放入模式中。
这是我的工作向导:plunker http://plnkr.co/edit/achnwMtmebR3oc8bq7pp?p=preview
这是我的工作模式:http://plnkr.co/edit/ux1Ju6m2s9VqiIPjmH1n?p=preview
如何将此工作向导添加到模式中?嵌套状态可以是多个状态还是限制为不超过两个?
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
// route to show our basic form (/form)
.state('form', {
url: '/form',
templateUrl: 'form.html',
controller: 'formController'
})
// nested states
// each of these sections will have their own view
// url will be nested (/form/profile)
.state('form.profile', {
url: '/profile',
templateUrl: 'form-profile.html'
})
// url will be /form/interests
.state('form.interests', {
url: '/interests',
templateUrl: 'form-interests.html'
})
// url will be /form/payment
.state('form.payment', {
url: '/payment',
templateUrl: 'form-payment.html'
});
// catch all route
// send users to the form page
$urlRouterProvider.otherwise('/form/profile');
})
最好不要将路由放在模态框内。您最好编写自己的表单步骤。逻辑很简单。您不需要单独的路线。当按下 "next" 按钮时,您将增加 pageNumber
。您可以为每个页面放置不同的 div
。您可以使用 ng-show
或 ng-hide
指令 hide/show 页面。
只需合并您的 HTML 和 JS 文件,将 ui-view
移入模态
HTML:
<body ng-app="formApp">
<div ng-controller="MainCtrl as mainCtrl">
<button type="button"
class="btn btn-default"
ng-click="mainCtrl.page.open()">Open Modal</button>
<!-- modal -->
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title" id="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body" id="modal-body">
<!-- views will be injected here -->
<div class="container">
<div ui-view></div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default pull-left"
type="button"
ng-click="modalInstanceCtrl.modal.cancel()">Cancel</button>
</div>
</script>
</div>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="jumbotron text-muted text-center">
<p>a tutorial by <a href="http://scotch.io" target="_blank">scotch.io</a></p>
<p><a href="http://scotch.io/tutorials/javascript/angularjs-multi-step-form-using-ui-router">Create a Multi-Step Form Using Angular and UI-Router</a></p>
</div>
</div>
</div>
</body>
我想将步骤向导放入模式中。
这是我的工作向导:plunker http://plnkr.co/edit/achnwMtmebR3oc8bq7pp?p=preview
这是我的工作模式:http://plnkr.co/edit/ux1Ju6m2s9VqiIPjmH1n?p=preview
如何将此工作向导添加到模式中?嵌套状态可以是多个状态还是限制为不超过两个?
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
// route to show our basic form (/form)
.state('form', {
url: '/form',
templateUrl: 'form.html',
controller: 'formController'
})
// nested states
// each of these sections will have their own view
// url will be nested (/form/profile)
.state('form.profile', {
url: '/profile',
templateUrl: 'form-profile.html'
})
// url will be /form/interests
.state('form.interests', {
url: '/interests',
templateUrl: 'form-interests.html'
})
// url will be /form/payment
.state('form.payment', {
url: '/payment',
templateUrl: 'form-payment.html'
});
// catch all route
// send users to the form page
$urlRouterProvider.otherwise('/form/profile');
})
最好不要将路由放在模态框内。您最好编写自己的表单步骤。逻辑很简单。您不需要单独的路线。当按下 "next" 按钮时,您将增加 pageNumber
。您可以为每个页面放置不同的 div
。您可以使用 ng-show
或 ng-hide
指令 hide/show 页面。
只需合并您的 HTML 和 JS 文件,将 ui-view
移入模态
HTML:
<body ng-app="formApp">
<div ng-controller="MainCtrl as mainCtrl">
<button type="button"
class="btn btn-default"
ng-click="mainCtrl.page.open()">Open Modal</button>
<!-- modal -->
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title" id="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body" id="modal-body">
<!-- views will be injected here -->
<div class="container">
<div ui-view></div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default pull-left"
type="button"
ng-click="modalInstanceCtrl.modal.cancel()">Cancel</button>
</div>
</script>
</div>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="jumbotron text-muted text-center">
<p>a tutorial by <a href="http://scotch.io" target="_blank">scotch.io</a></p>
<p><a href="http://scotch.io/tutorials/javascript/angularjs-multi-step-form-using-ui-router">Create a Multi-Step Form Using Angular and UI-Router</a></p>
</div>
</div>
</div>
</body>