Defining a resource URL globally.

37 views
Skip to first unread message

Dan Martin

unread,
Aug 27, 2014, 3:01:33 PM8/27/14
to ang...@googlegroups.com
I'm working on a hybrid (Ionic - AngularJS-based mobile framework) mobile application that has an embedded NoSQL datastore, Couchbase Lite.  CBL plug-in for PhoneGap/Cordova/Ionic only provides a method for retrieving the URL of the embedded DB.  And it seems like it's only accessible "on device ready" (I tried calling the function else where and didn't work).

I was hoping to resolve the URL during Angular's bootstrap phase and save it to the rootScope so it's accessible elsewhere in the application, particularly in my services, but this didn't work either.

I'm kind of stuck because there is no other way for me to provide a URL for my resources.


Thoughts...solutions??


Thanks,
Dan

Luke Kende

unread,
Aug 28, 2014, 2:06:03 AM8/28/14
to ang...@googlegroups.com
$watch in app.run and broadcast event to controllers, you'll need some loading screen.  It's timing, you control that by not letting things execute until they are ready.  You can also wait until the value is present before bootstrapping angular if you prefer.

Dan Martin

unread,
Sep 12, 2014, 11:03:22 AM9/12/14
to ang...@googlegroups.com
Luke, thanks to your suggestion, I was able to get passed this.  

I broadcast an event that gets fired when the app becomes ready/available from within app.run (as you suggested).  Then, I have a DB service that reacts on the event, retrieving the CBL URL (via CBL plugin) and saves it in memory (variable) for future DB requests (via REST) from my factories. 

Luke Kende

unread,
Sep 12, 2014, 11:50:07 AM9/12/14
to ang...@googlegroups.com
Great!  Glad that got you going.  Timing is one of the bigger challenges with angular I have found.  For example, I have my app set up such that initial data is loaded in app.run and once all xhr calls are complete, it then sets a ready variable on $rootScope. Each controller $watches this variable such that no matter what URL a user comes in to the app on, certain routines don't fire until that ready variable is set.  It only has to be set that one time for the life of the app (until a refresh).



--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/1_XmE63Yq30/unsubscribe.
To unsubscribe from this group and all its topics, 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/d/optout.

Reply all
Reply to author
Forward
0 new messages