z-core icon indicating copy to clipboard operation
z-core copied to clipboard

Z as an angularjs service

Open gilelad opened this issue 10 years ago • 1 comments

I'd like to use Z in my angularjs app. How can I make Z use angularjs's $q service object to create its promises?

gilelad avatar Dec 01 '14 11:12 gilelad

It's quite possible to adapt Z to work with angulars promises, but they are not constructed the same way as the native ones, so some refactoring will be required. I don't mind doing it and it will probably make it easier for people to start using the library :)

Before that has been done, there is another quite easy solution you can use:

  • Get a polyfill for native promises (so your app will work outside of chrome/firefox). For example this one: https://github.com/jakearchibald/es6-promise
  • Then use Z as you would do in the usual case, without angular. It won't be an angular service, but rather a global variable.

Then you can do things like Z(some$qPromise).toLowerCase() and so on.

If you run bindSync or bindAsync on your functions, they will not only accept Z-promises (native promises, that is), but all types of A+ promises, including angulars $q-promises. So there's not even an adaptation required there. Just use bindSync/bindAsync on your functions to make them promise-ready and you're good to go.

I'll let you know when I've made Z available as an angular service directly ;)

jakobmattsson avatar Dec 02 '14 07:12 jakobmattsson