Error: The function $scope.apply is invalid and cannot be executed

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();

    });

};

Answer №1

Use the $apply() function, incorporating the symbol $.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to divide my value sets using jQuery?

Within a given string such as 28_34/42/34,23_21/67/12,63_5/6/56, I am seeking to split or eliminate sets based on the ID provided. For example, if the ID is 23, then the set 23_21/67/12 should be removed. To achieve this, I am checking the value after the ...

"Generate a series of dropdown menus with choices using either jQuery or AngularJS from a JSON dataset

I'm in need of assistance. I want to generate select dropdowns dynamically based on data retrieved from my REST API, which is in JSON format. How can I dynamically inject these selects into my HTML? Below is an example data structure: JSON data fetch ...

In search of an effortless method to effortlessly select numerous elements using a handy bookmarklet

My goal is to develop a bookmarklet that can perform various functions on different webpages with ease. The concept involves placing it in a convenient location, such as the bookmark bar, and executing a "standard function" on a particular page. Instead of ...

How can we pass the onClick prop from a child component to a parent component in React with Typescript?

Currently, I am utilizing React along with TypeScript. I am curious about the process of passing an event from the parent component to a child component using props. Here is an example for better understanding: parent.tsx const ParentComponent: React.F ...

Tips for executing getJSON requests one after the other

My goal is to showcase a weather forecast for a specific date on my website. Here are excerpts from the code I've used on a trial page that isn't functioning correctly: <script> function displayWeather(date){ $.getJSON(url + apiKey + "/" ...

Tips on programmatically filtering angular lists

Is there a way to programmatically filter an Angular list? I'm currently working on a project where I need to filter subcategories by clicking on categories. For example, when clicking on "Drinks," I want to display items like Coke, Fanta, Pepsi... ...

The combination of Angular and Google Tag Manager (GTM) for tracking user clicks is highly effective

I've encountered a puzzling issue that I can't seem to resolve. The marketing department has expressed interest in integrating GTM in order to have full control over third-party providers, particularly focusing on tracking all clicks on a page. ...

Send PS3 through user agent for redirection

If a user is accessing the site using a PS3, I want them to be redirected to a different webpage Below is the code snippet I have been attempting to use: <script language=javascript> <!-- if ((navigator.userAgent.match(/iMozilla/i)) || (navigato ...

Activate a tooltip in Vuetify

I'm utilizing vuetify and have implemented a tooltip feature on a button. However, I do not want the tooltip to be displayed on hover or click; instead, I would like it to appear when a specific event is triggered. translate.vue <v-tooltip v-model ...

Querying MongoDB with a JavaScript file for formatting datetime values

I am utilizing mongodb3.0.5 and my database collection appears as follows: { "_id" : "xxxxxxxxxxxxxxx", "SchoolId" : 1, "ActivationTimestamp" : ISODate("2015-09-22T13:01:58.000Z"), "PersonDetails" : [ { "Name" : "John" ...

Angular allows me to use the $http.get method to retrieve the HTML content of my index

This strange issue has been plaguing me - I apologize in advance for the lengthy code, but I believe it's necessary for you to understand my problem. Here is what I have in my index.html: <!DOCTYPE html> <html ng-app="mainApp"><!--Boot ...

Add a new sibling item to Angular-UI-tree

I am trying to add a sibling item to a tree when clicked in angular-ui-tree (https://github.com/angular-ui-tree/angular-ui-tree) Here is an example of what I currently have: <item><input value"item A #1"><button>insert under</button& ...

"Internet Explorer text input detecting a keyboard event triggered by the user typing in a

It appears that the onkeyup event is not triggered in IE8/IE9 (uncertain about 10) when the enter button is pressed in an input box, if a button element is present on the page. <html> <head> <script> function onku(id, e) { var keyC = ...

Error occurred due to an unexpected end of JSON input following a pending promise

I am currently developing a data handler that requires downloading a file for parsing and processing within the handler. To handle this, I have implemented the file request within a promise and called it asynchronously from other methods. Including the h ...

Retrieving server information using AJAX in React

I've been attempting to utilize an AJAX call in order to fetch server data for my React Components. However, I'm encountering difficulties when it comes to displaying it with React as I keep receiving this error: Uncaught TypeError: Cannot read ...

What could be causing my update function to not run when I refresh the page?

As a non-developer trying to learn react.js, I am working on a section of my website that needs to update every few seconds with new content like a photo, header, and body text. I've encountered an issue where the data refreshes correctly after the p ...

Is there a way to detect and intercept M-SEARCH requests in Express?

Here is my Express program designed to capture M-SEARCH requests: router['m-search']('/', function(req, res, next) { res.send('Received an M-SEARCH request\n'); }); This code specifically responds to the following r ...

Optimizing your approach to testing deferred always

When creating test cases for code within a jQuery AJAX call's always method or in bluebird promises' finally function, it often involves the following structure: function doStuff() { console.log('stuff done'); } function someFunct ...

Tips for managing modal closure when the InertiaJS form succeeds?

Hello everyone! Currently, I'm involved in a Laravel project where I am using laravel/breeze VueJS with Inertia. The login functionality is implemented using a bootstrap modal component. While validation and authentication are working smoothly, the on ...

Conceal a certain element in development using CSS

Is there a way to hide the footer section from my webpage without affecting the rest of the content? For example, using something like: "div class="poweredby" display: none", but I'm unsure of the correct method... Here is the spe ...