TypeError: $scope.apply is not a function

All we need is an easy explanation of the problem, so here it is.

I am trying to render the contacts list after retrieving it thru rdflib.js. It is loading properly and saving it in the list inside the scope.

But I am not able to render sine the $scope doesn’t update, it seems like I am calling $scope.apply() in the wrong place. The error occurs because I call it outside angular, but I am deliberately calling it inside the function that is outside angular context (nowOrWhenFetched), so not making sense for me. any help?

$scope.load = function () {
    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 






How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

The function is $apply(), with the $.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply