我正在学习如何将$ 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)}]);
答案 0 :(得分:1)
您忘记在控制器依赖项数组中注入$q
依赖项。应用程序崩溃了,因为$q
是undefined
& undefined
.defer()
发生错误。
<强>代码强>
app.controller('NameController', ['$scope', '$q', //<--you need to inject it here.
function($scope, $q) {
scope.names = playerNames($q)
}
]);