I am attempting to display the contacts list after retrieving it using rdflib.js
. The data is being loaded and stored in the list within the scope.
However, I am running into an issue where the $scope is not updating, and it appears that I may be calling $scope.apply()
in the incorrect location. The error seems to occur because I am calling it outside of Angular, but I am intentionally calling it within a function that is outside of the Angular context (nowOrWhenFetched
), so I'm having trouble understanding why this isn't working. Any assistance would be appreciated.
$scope.load = function () {
//$scope.getContactsList();
var g = $rdf.graph();
var f = $rdf.fetcher(g);
f.nowOrWhenFetched($scope.path + '*',undefined,function(){
var DC = $rdf.Namespace('http://purl.org/dc/elements/1.1/');
var RDF = $rdf.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
var LDP = $rdf.Namespace('http://www.w3.org/ns/ldp#');
//var myOntology = $rdf.Namespace('http://user.pds.org/ontology/');
var VCARD = $rdf.Namespace('http://www.w3.org/2006/vcard/ns#');
var evs = g.statementsMatching(undefined, RDF('type'), VCARD('Individual'));
if (evs != undefined) {
for (var e in evs) {
var id = evs[e]['subject']['value'];
var fullname = g.anyStatementMatching(evs[e]['subject'], VCARD('fn'))['object']['value'];
var email = g.anyStatementMatching(evs[e]['subject'], VCARD('hasEmail'))['object']['value'];
var phone = g.anyStatementMatching(evs[e]['subject'], VCARD('hasTelephone'))['object']['value'];
var contact = {
id: id.slice(id.length-1),
Name: fullname,
Email: email,
Phone: phone
};
$scope.contacts.push(contact);
}
}
$scope.apply();
});
};