Passing data into AngularJS UI Bootstrap $modal

11,974 views
Skip to first unread message

Francesco Rizzi

unread,
Jan 28, 2014, 10:08:38 AM1/28/14
to ang...@googlegroups.com
Hello everyone.
I've been struggling for a while on this one, and haven't quite solved it yet, so... I hope someone can show me the light.
As you can see from index.html, I'm trying to use
Bootstrap 3.0.3
AngularJS 1.2.9
Angular UI Bootstrao 0.10.0

index leads to MyApp.js, which sets up simple routing to home.html and HomeCtrl.
Now, HomeCtrl uses the $modal service to create a modal instance ($modal.open), using _modal.html as template and ModalCtrl as controller.

_home.html as hard-coded "Title" and "Message" for the modal dialog and it all seems to work fine.

However, when I try to make HomeCtrl pass variables into the instance, I start failing. I've tried a few things based on the samples I could find around (the canonical Angular UI bootstrap sample for modal passes a list of items), but none quite worked.

Could you show me how I should go by having HomeCtrl "pass in" a title and message so that the _modal.html can display them instead of the hardcoded values?
( I'm not showing any of my attempts so far because I don't want to "lead the witness" down the path of using resolve, or adding the variables to $scope or anything else )

Thank you,
FR

Edmilson Lani

unread,
Jan 28, 2014, 2:05:08 PM1/28/14
to ang...@googlegroups.com


2014-01-28 Francesco Rizzi <frances...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.



--
Atenciosamente
Edmilson Lani

Francesco Rizzi

unread,
Jan 28, 2014, 2:19:11 PM1/28/14
to ang...@googlegroups.com
Yes, **Thank you**
So...
1) my instinct was then to try and pass the two pieces of data as a single "model", eg: http://plnkr.co/edit/dkZ1AQjcdCnuoZk6Gz6d?p=preview

2) I wonder if the (or part of the) problem was that I was declaring the ModalCtrl in its own module
angular.module('myapp.controllers.modal', ['ui.bootstrap',]).controller( /* etc etc */)

Hmm... anyways, I think your solution works fine for my case: Thanks again!
FR

Craig Kahle

unread,
Oct 23, 2014, 1:08:44 PM10/23/14
to ang...@googlegroups.com
Edmilson.... Thank you so much. Very helpful.

-Craig

lokesh.c...@gmail.com

unread,
Feb 18, 2016, 7:47:49 AM2/18/16
to AngularJS
Thank u . It really helped me.
Reply all
Reply to author
Forward
0 new messages