$ q.when不是功能?
问题描述:
我试图创建一个简单的应用程序,它有详细视图的主力名单,但我不能让过去的这个错误:
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,重新安排这一点,它会工作。
谢谢!这样一个简单的修复 –