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

时间:2015-11-01 21:51:57

标签: angularjs angular-promise

我正在学习如何将$ 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)}]);

1 个答案:

答案 0 :(得分:1)

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

<强>代码

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