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,请重新排序,它将正常工作。谢谢!这么简单的解决办法