11

I am getting this error in the console $q is not defined. When I did some research I found some thing like .q library has been deprecated from http://www.breezejs.com/documentation/breeze-labs/breezeangularqjs

If this is so, then the whole concept of promises is also deprecated,

Benjamin Gruenbaum
277k90 gold badges524 silver badges523 bronze badges
asked Mar 13, 2014 at 13:11
2
  • 2
    Have you injected $q into the scope you're working in? Commented Mar 13, 2014 at 13:14
  • Please consider updating us on progress and giving me feedback on the answer :) Commented Apr 4, 2014 at 9:00

2 Answers 2

25

Promises are not deprecated. In fact they're gaining quite a lot of momentum lately and are included in the next version of JavaScript.

Let's look at what they say:

This breeze.angular.q library has been deprecated. It is superseded by the Breeze Angular Service which more cleanly configures breeze for Angular development.

The Breeze Angular Service tells Breeze to use Angular's $q for promises and to use Angular's $http for ajax calls.

What they say is that breeze uses Angular's own promises for promises rather than its own breeze.angular.q which uses Q promises which are more able but also much heavier than $q promises which Angular uses. This is simply an API change.

Inside Angular code, you can obtain $q using dependency injection - for example with the simple syntax:

myApp.controller("MyCtrl",function($q){
 //$q is available here
});

Alternatively, if you want to use it independently you can use service location and obtain $q directly from an injector, but that's rarely the case. (If you want an example - let me know, I'd just rather not include code that's usually indicative of bad practice).

answered Mar 13, 2014 at 13:13
2
  • Hey, thanks, at first i would like to agree that i am not that familiar about angular concepts, So while searching through the promises documents, i found techjini.com/blog/javascript-promises, Is this documentation is correct, If not correct me . Thanks a lot Brother Commented Mar 13, 2014 at 14:09
  • @RaviMone if you create a short example on jsfiddle (jsfiddle.com) or another such website I can take a look and try to understand what you're doing wrong. Commented Mar 13, 2014 at 14:12
9
# in your console, try following code
$injector = angular.injector(['ng']);
q = $injector.get('$q');
deferred = q.defer();
# then do whatever you want
answered Jun 11, 2014 at 8:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.