Mardymar
Mardymar

Reputation: 419

Crash when using $q on an angularjs and parse app

I am learning how to use $q for asynchronous code. I have not found any information about how to use this for a function outside of the controller function. I have the code below and it crashes right after the $q.defer() line and I don't know why.

function playerNames($q) {

Parse.$ = jQuery;

Parse.initialize("mykey", "mykey");

var namesdfd = $q.defer();
.
.
.
};

app.controller('NameController', ['$scope', function($scope, $q) {scope.names = playerNames($q)}]);

Upvotes: 1

Views: 48

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136154

You forgot to inject $q dependency inside your controller Dependency array. Application was getting crashed because you have $q which is undefined & undefined's .defer() throwing an error.

Code

app.controller('NameController', ['$scope', '$q', //<--you need to inject it here.
  function($scope, $q) {
   scope.names = playerNames($q)
  }
]);

Upvotes: 1

Related Questions