Sunday, December 28, 2014

Modal dialog box and popups in Angular.js using ngDialog


If you are building an Angular.js application and wish to add a modal dialog box or a simple popup, then the ngDialog module provides an easy, simple solution. It provides two default css themes and we can also add our own custom themes.

Let's see how to create a simple dialog box with ngDialog.
For our example, we will have a base page with a button which when clicked will open a contact-us form as dialog box. The dialog box will have an 'OK' button which will save the changes and close the box and a 'Cancel' button which will just dismiss the box.

1. First, you need to download ngDialog.js and ngDialog.css (and the themes that you want) from https://github.com/likeastore/ngDialog

2. Create the base template - 'base.html'


3. Create the dialog box template - 'contact_us.html'

closeThisDialog() and confirm() are ngDialog's methods and they return an Angular promise object that is either rejected or resolved.

4. Angular.js code to handle the promise:

Now if you wish to add a popup message as per the response success or failure:

The plain option, if set to 'true' allows to use a plain string as template.
The API also provides a lot of other useful options and event handlers.


11 comments:

  1. Excelente que bueno estaba buscando esto y no lo encontré en otra parte muy bueno aunque no me sale llamando a un HTML externo me sale con un script dentro del mismo base html

    ReplyDelete
  2. I really like your article. You’ve mentioned steps which can be easily understood. Check out Yiioverflowto know more about Angular JS development.https://yiioverflow.com/

    ReplyDelete
  3. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!
    Online training in USA

    ReplyDelete
  4. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here. we are providing AngularJs training in velachery.
    for more details: AngularJs training in velachery

    ReplyDelete

  5. Thank you for your great post. Eligible travelers who want to get medical visa India can easily complete the application by providing some required details. Medical visa is a short term visa granted for medical treatment reasons.

    ReplyDelete