Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Error: $q is not defined

I want to make a promise in my angularjs controller. I took the example from the Angularjs Doc and pasted it in my controller. When I try to run the code, the console prints:

Error: $q is not defined

Why is this error happening and how do I solve it?

I tried to google this problem, but most questions revolve about more specific problems than mine.

A (german) guide tells me that promises are already in angular js implemented and there is no need to add anything to it.

EDIT:

this is my controller:

app.controller("ArgumentationController", [
    '$scope', '$resource',
    function($scope, $resource) {

EDIT2: A commentor suggested to inject $q. I did this:

app.controller("ArgumentationController", [
    '$scope', '$resource', '$q',
    function($scope, $resource, $q) {

Now, the error does not occur.

like image 614
Metaphysiker Avatar asked Dec 17 '16 16:12

Metaphysiker


1 Answers

From your past code, no need of $resource in your code. Instead inject $q in it. As you are creating a dummy promise using $q, make following changes.

 app.controller("ArgumentationController", [
        '$scope', '$q',
        function($scope, $q) {
like image 59
Sai Avatar answered Nov 05 '22 15:11

Sai