在 angularjs 上使用 $q 并解析应用程序时崩溃

Crash when using $q on an angularjs and parse app

我正在学习如何将 $q 用于异步代码。我还没有找到任何关于如何将它用于控制器功能之外的功能的信息。我有下面的代码,它在 $q.defer() 行之后立即崩溃,我不知道为什么。

function playerNames($q) {

Parse.$ = jQuery;

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

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

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

您忘记在控制器依赖项数组中注入 $q 依赖项。应用程序崩溃是因为 $qundefined & undefined.defer() 抛出错误。

代码

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