I’ve been learning ui-router and I’d like to share some things I’ve learned that took me a while to get. With bits of Ionic Framework.
Let’s say you have an abstract state with a child and another state and you want to trigger a transition from the
controller to the other state. The following is a concrete example. I was building an ionic app that would grab a photo
from the phones photolibrary and transition to another view, passing the fetched uri to the new view.
app.js
Here we set up all the states in our app. Note that the ‘crop-image’ state is going to require an ‘:imageURI’ param in
it’s url.
The AppController is the main controller for this app. Accessible from any state inheriting from the app abstract
state declared in app.js. Notice how we are fetching a uri from the photolibrary and passing it as a parameter for the
CropController. We must first call encodeURIComponent() on this uri to pass the value around. Otherwise ui-router
get’s confused - loading CropController but failing to change the url or load the template.
camera-service.js
In camera-service.js we’ve wrapped all calls to the cordova-plugin-camera in an agularjs service. This is a good solution until the Ionic Framework provides guidance on interfacing with
cordova plugins. See How to use Cordova plugins ….
tbc
If you need help solving your business problems with
software read how to hire me.