Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $q.什么时候不是函数?_Javascript_Html_Angularjs_Ionic Framework - Fatal编程技术网

Javascript $q.什么时候不是函数?

Javascript $q.什么时候不是函数?,javascript,html,angularjs,ionic-framework,Javascript,Html,Angularjs,Ionic Framework,我正在尝试创建一个简单的应用程序,它有一个包含详细视图的主列表,但我无法克服此错误: ionic.bundle.js:26794 TypeError: $q.when is not a function at Object.getAllObjects (app.services.js:13) at app.controller.js:11 at ionic.bundle.js:56230 at Object.ready (ionic.bundle.js:2140) at Object

我正在尝试创建一个简单的应用程序,它有一个包含详细视图的主列表,但我无法克服此错误:

ionic.bundle.js:26794       TypeError: $q.when is not a function
at Object.getAllObjects (app.services.js:13)
at app.controller.js:11
at ionic.bundle.js:56230
at Object.ready (ionic.bundle.js:2140)
at Object.ready (ionic.bundle.js:56223)
at new MainController (app.controller.js:7)
at Object.instantiate (ionic.bundle.js:18010)
at $controller (ionic.bundle.js:23412)
at self.appendViewElement (ionic.bundle.js:59900)
at Object.render (ionic.bundle.js:57893)
它所指的代码是:

app.factory('DatabaseService', ['$q', '$http','$rootScope',

function DatabaseService( $rootScope, $q, $http) {  
var _db;    


var _content;

return {
    initDB: initDB,
    getAllObjects: function getAllObjects() {  
if (!_content) {
   return $q.when(_db.allDocs({ include_docs: true}))
        .then(function(docs) {


            _content= docs.rows.map(function(row) {

                return row.doc;
            });


            _db.changes({ live: true, since: 'now', include_docs: true})
               .on('change', onDatabaseChange);

            return _content;
        });
} else {

    return $q.when(_content);
}
},
getObject: function getObject(id){
  var index = findIndex(($rootScope._content),id);
  return $rootScope._content[index];
}

};

似乎所有的依赖项都是正确的,那么为什么我会遇到这个奇怪的错误呢?似乎我最近的大多数错误都是“非函数”错误,但我不知道为什么

您混合了注射剂:

['$q', '$http','$rootScope',function DatabaseService( 
  $rootScope, $q, $http) {  ...}

因此,事实上,您的$q包含$http,请重新排序,它将正常工作。

谢谢!这么简单的解决办法