I am attempting to implement a filter that will provide either a success or error response from the ret()
function. The current code is returning {}
, which I believe is its promise.
.filter('postcode', ['$cordovaSQLite', '$q',
function($cordovaSQLite, $q) {
return function(PostCodeID) {
function ret() {
var def = $q.defer();
ionic.Platform.ready(function() {
if (window.cordova) {
var db = $cordovaSQLite.openDB({
name: "msddocapp.db"
});
} else {
var db = window.openDatabase("msddocapp.db", "1", "ES Database", 5 * 1024 * 1024);
}
var query = "select * from PostCode where ServerID = ?";
$cordovaSQLite.execute(db, query, [PostCodeID]).then(function(s) {
if (s.rows.length > 0) {
def.resolve(s.rows.item(0).Title);
}
}, function(e) {
console.log(e);
def.reject(PostCodeID);
})
});
return def.promise;
}
return ret().then(function(s) {
return s;
}, function(e) {
return e;
});
}
}]);
This filter is specifically for a single ng-repeat
, so perhaps I could attach a function directly to ng-repeat like:
HTML
{{getPostName(item.id)}}
Angular.js
function getPostName(id) {
return post[id].name;
}