Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
Ng2 Bootstrap Modal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Globars Forks
Ng2 Bootstrap Modal
Commits
a8fd5fad
Commit
a8fd5fad
authored
Jan 23, 2017
by
avovchuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
readme - quickstart
parent
eb9932e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
125 additions
and
0 deletions
+125
-0
README.md
README.md
+125
-0
No files found.
README.md
View file @
a8fd5fad
#Angular2 Bootstrap Modal Service
Library to simplify the work with bootstrap modal dialogs
##Quickstart
### Step 1. import '**BootstrapModalModule**' module
app.module.ts:
```
typescript
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
CommonModule
}
from
"
@angular/common
"
;
import
{
BootstrapModalModule
}
from
'
ng2-bootstrap-modal
'
;
import
{
AppComponent
}
from
'
./app.component
'
;
@
NgModule
({
declarations
:
[
AppComponent
],
imports
:
[
CommonModule
,
BootstrapModalModule
]
})
export
class
AppModule
{}
```
###Step 2. Create your modal dialog component
Your modal dialog should be extended from
**DialogComponent**
.
**DialogComponent**
waits
**DialogService**
as constructor argument.
confirm.component.ts:
```
typescript
import
{
Component
}
from
'
@angular/core
'
;
import
{
DialogComponent
,
DialogService
}
from
"
ng2-bootstrap-modal
"
;
@
Component
({
selector
:
'
confirm
'
,
template
:
`<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" (click)="close()" >×</button>
<h4 class="modal-title">{{title || 'Confirm'}}</h4>
</div>
<div class="modal-body">
<p>{{message || 'Are you sure?'}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="confirm()">OK</button>
<button type="button" class="btn btn-default" (click)="close()" >Cancel</button>
</div>
</div>`
})
export
class
ConfirmComponent
extends
DialogComponent
{
constructor
(
dialogService
:
DialogService
)
{
super
(
dialogService
);
}
confirm
()
{
this
.
result
=
true
;
this
.
close
();
}
}
```
###Step 3. Register created component to module
Add component to
**declarations**
and
**entryComponents**
section because component
will be created dynamically.
app.module.ts:
```
typescript
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
CommonModule
}
from
"
@angular/common
"
;
import
{
BootstrapModalModule
}
from
'
ng2-bootstrap-modal
'
;
import
{
ConfirmComponent
}
from
'
./confirm.component.ts
'
;
@
NgModule
({
declarations
:
[
ConfirmComponent
],
imports
:
[
CommonModule
,
BootstrapModalModule
],
//Don't forget add component to **entryComponents** section
entryComponents
:
[
ConfirmComponent
]
})
export
class
AppModule
{}
```
###Step 4. Usage
app.component.ts
```
typescript
import
{
Component
}
from
'
@angular/core
'
;
import
{
ConfirmComponent
}
from
'
./confirm.component.ts
'
;
import
{
DialogService
}
from
"
ng2-bootstrap-modal
"
;
@
Component
({
selector
:
'
app
'
,
template
:
`
<div class="container">
<button class="btn btn-default" (click)=showConfirm()>Show confirm</button>
</div>
`
})
export
class
AppComponent
{
constructor
(
private
dialogService
:
DialogService
)
{}
showConfirm
()
{
let
disposable
=
this
.
dialogService
.
addDialog
(
ConfirmComponent
,
{
title
:
'
Confirm title
'
,
message
:
'
Confirm message
'
}).
subscribe
((
isConfirmed
)
=>
{
if
(
isConfirmed
)
{
alert
(
'
accepted
'
);
}
else
{
alert
(
'
declined
'
);
}
});
//If dialog was not closed manually close it by timeout
setTimeout
(()
=>
{
disposable
.
unsubscribe
();
},
10000
);
}
}
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment