I am trying to find some examples on how to do a Confirmation modal dialog in Angular 2.0. I have been using Bootstrap dialog for Angular 1.0 and unable to find any examples in the web for Angular 2.0. I also checked angular 2.0 docs with no luck.
Is there a way to use the Bootstrap dialog with Angular 2.0?
Thanks!
Now available as a NPM package
angular-custom-modal
@Stephen Paul continuation...
ngOnDestroy
(ed) when the modal is exited.Lazy content initialization
Why?
In some cases you might not want to modal to retain its status after having been closed, but rather restored to the initial state.
Original modal issue
Passing the content straightforward into the view actually generates initializes it even before the modal gets it. The modal doesn't have a way to kill such content even if using a
*ngIf
wrapper.Solution
ng-template
.ng-template
doesn't render until ordered to do so.my-component.module.ts
my-component.ts
modal.component.ts
modal.component.html
References
I have to say that it wouldn't have been possible without the excellent official and community documentation around the net. It might help some of you too to understand better how
ng-template
,*ngTemplateOutlet
and@ContentChild
work.https://angular.io/api/common/NgTemplateOutlet
https://blog.angular-university.io/angular-ng-template-ng-container-ngtemplateoutlet/
https://medium.com/claritydesignsystem/ng-content-the-hidden-docs-96a29d70d11b
https://netbasal.com/understanding-viewchildren-contentchildren-and-querylist-in-angular-896b0c689f6e
https://netbasal.com/understanding-viewchildren-contentchildren-and-querylist-in-angular-896b0c689f6e
Full copy-paste solution
modal.component.html
modal.component.ts
modal.module.ts
Here is my full implementation of modal bootstrap angular2 component:
I assume that in your main index.html file (with
<html>
and<body>
tags) at the bottom of<body>
tag you have:modal.component.ts:
modal.html:
And example of usage in client Editor component: client-edit-component.ts:
client-edit.html:
Ofcourse
title
,showClose
,<mhead>
and<mfoot>
ar optional parameters/tags.I use ngx-bootstrap for my project.
You can find the demo here
The github is here
How to use:
Install ngx-bootstrap
Import to your module
I recently blogged about this ..
I created a reusable service which a component can have injected. Once injected, the component can communicate to the service whether it is in a dirty state and tie into router navigation.
https://long2know.com/2017/01/angular2-menus-navigation-and-dialogs/ https://long2know.com/2017/01/angular2-dialogservice-exploring-bootstrap-part-2/
This is a simple approach that does not depend on jquery or any other library except Angular 2. The component below (errorMessage.ts) can be used as a child view of any other component. It is simply a bootstrap modal that is always open or shown. It's visibility is governed by the ngIf statement.
errorMessage.ts
errorMessage.html
This is an example parent control (some non-relevant code has been omitted for brevity):
parent.ts
parent.html
Check ASUI dialog which create at runtime. There is no need of hide and show logic. Simply service will create a component at runtime using AOT ASUI NPM