如何开始使用$q?

How to start using $q?

我试过像这样在我的控制器中注入 $q:

app.controller('NodeCtrl', ['Tree', function(Tree, $scope, $element, $q) {

但是,$q没有定义,我该如何开始使用呢?我正在使用 Angular 1.4

您需要注入它并将其添加到您的参数列表中:

app.controller('NodeCtrl', ['Tree', '$scope', '$element', '$q', 
               function(Tree, $scope, $element, $q) {