AngularJS module that adds support for ui-bootstrap modal states when using ui-router.
npm install angular-ui-router-uib-modalangular-ui-router-uib-modal
===========================

AngularJS module that adds support for ui-bootstrap modal states when using ui-router.
Motivation
----------
Some RIAs using UI-Router use modal dialogs for certain application states.
The UI-Router's FAQ,
shows how to implement modal dialogs using ui.bootstrap.modal service.
While it works well, it requires a lot of boiler-plate code, complicates the state definition, and requires the state
controller to be aware that its inside a $uibModalInstance to automatically close the dialog on a state change.
This module gets rid of the boilerplate by adding support for a modal: true option in state definitions.
This causes the state to be displayed via $uibModal.open(...) instead of within a .
Installing the Module
---------------------
Installation can be done through bower or npm:
`` shell`
bower install angular-ui-router-uib-modal
In your page add:
`html`
Loading the Module
------------------
This module declares itself as ui.router.modal, so it can be declared as a dependency of your application as normal:
`javascript`
var app = angular.module('myApp', ['ng', 'ui.router', 'ui.bootstrap', 'ui.router.modal']);
Specifying modal states
-----------------------
Adding a modal: true to a state definition causes its template to be opened through a call to$uibModal.open(stateDefinition)
rather than embedding it inside of a .true
To specify which resolved state values are available to the modal controller, use an array instead of ,modal: ['value1', 'value2']
e.g. .
Inside the modal state controller, the modal via can be closed via $uibModalInstance.close/dismiss() or by $state.go('^')
transitioning to the parent state via .
Caveats Modal does not have access to parent state's The modal's You must specify resolved parent state values to provide to the modal controller By default, In the following examples, The module uses the current Does not work with custom Copyright & License Copyright 2016 Stepan Riha. All Rights Reserved. This may be redistributed under the MIT licence. For the full license terms, see the LICENSE file which
`javascript
$stateProvider
.state('contacts', {
url: '/contacts',
// ...
})
.state('contacts.contact', {
url: '/:contactId',
modal: true,
template: '...',
controller: function($scope, $state, contact) {
$scope.close = function() {
$state.go('^');
}
},
resolve: {
// Single contact
contact: ['Contacts', '$stateParams', function(Contacts, $stateParams) {
// Use Contacts service to retrieve a contact
return Contacts.get({ id: $stateParams.contactId });
}]
}
})
`$scope
------- values$scope doesn't inherit anything from the parent state's scope. So anyresolve
data that comes from the parent should be specified via settings.$uibModal.open() is called with only the resolved values of the modal state. If you want to includetrue
values resolved in parent states, use an array instead of for the modal setting.$uibModal.open() for the parent.child state will be called with resolved valuesa, b, x, y and z.``
$stateProvider
.state('parent', {
...
resolve: {
a: ...,
b: ...,
c: ...
}
})
.state('parent.child', {
...
modal: ['a', 'b'],
resolve: {
x: ...,
y: ...,
z: ...
}
})$uibModal
Does not work with old versions of UI-Bootstrap service rather than the deprecated $modal.onEnter and onExit state configurationsonEnter
The module works by adding and onExit` state configurations to modal states.
If these are already defined in a modal state, an error is thrown.
-------------------
should be alongside this readme.