1
PouchDbサービスをAngular/Ionicで設定してサービス内で正常に動作しますが、PouchDBサービスから取得したデータをコントローラに渡そうとすると失敗します。PouchDBサービスからAngluarJSのコントローラにデータを渡す
は、これが私のサービス
angular.module('myApp', [])
.service('DBService', function($q) {
var items;
var db;
var self = this;
this.initDB = function() {
return db = new PouchDB('simpleDB', {
adapter: 'websql'
});
};
this.storeData = function() {
return $q.when(
db.put({
_id: 'mydoc',
title: 'some text'
}).then(function (response) {
// handle response
console.log('done')
}).catch(function (err) {
console.log(err);
})
)
};
this.getData = function(){
return $q.when(
db.get('mydoc').then(function (doc) {
// handle doc
console.log(doc); // I see the data in console
}).catch(function (err) {
console.log(err);
})
)
}
})
であると私は()私は、エラーTypeError例外を取得し、次に使用する場合、これは、コントローラ
angular.module('myApp', [])
.controller('mainCtrl', function($scope, DBService, $q) {
$scope.getData = function(){
DBService.initDB()
DBService.getData().then(function(data){
console.log(data)
})
}
です:未定義の「を」プロパティを読み取ることができません。
サービスからコントローラにデータを正しく渡す方法を教えてもらえますか?