AngularJS Controller failing to populate data

The following code snippet is designed to run on a SharePoint Web Part page within a Script Editor web part. It executes an AJAX call to retrieve list items from SharePoint and should then populate a form with the fetched items. However, no action seems to be taking place as expected.

    <link data-require="bootstrap-css@*" data-semver="3.0.0" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<h2>Questionnaire:</h2>
<br />
<div ng-app="App">
    <div ng-controller="spListCtrl">
        <table width="100%" cellpadding="10" cellspacing="2" class="employee-table">
            <tr ng-repeat="control in Controls">
                <td>{{control.Title}}</td>
                <td>
                    <input type="radio" name="{{control.Id}}" value="Yes">Yes
                    <input type="radio" name="{{control.Id}}" value="No">No
                </td>
                <td>
                    <textarea id="{{control.Id}}Comment"></textarea>
                </td>
            </tr>
        </table>
    </div>
</div>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.js"></script>
<script>
    function getDataWithCaml(listName, caml) {
        var endpoint = "https://myteamsite.sharepoint.com/_api/web/lists/GetByTitle('" + listName + "')/GetItems(query=@v1)?@v1={\"ViewXml\":\"'" + caml + "'\"}";
        return jQuery.ajax({
            url: endpoint,
            method: "POST",
            headers: {
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "Accept": "application/json;odata=verbose",
                "Content-Type": "application/json;odata=verbose"
            }
        });
    }

    var App = angular.module('App', ['ngRoute'])
    .controller('spListCtrl', function ($scope, $http) {
        var caml = "<View><Query><Where><Contains><FieldRef Name='Title' /><Value Type='Text'>C-04</Value></Contains></Where></Query></View>";
        var jsonData = getDataWithCaml("Controls", caml);
        jsonData.success(function (data) {
            alert('success');
            $scope.Controls = data.d.results;
        });
    });
</script>

Answer №1

To update the scope outside of Angular execution, it is important to wrap the assignment in $scope.$apply like this:

$scope.$apply(function() { 
  $scope.Controls = data.d.results;
});

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

Implementing pagination with complete page information using node.js and mongodb

Hello, I am currently working on implementing pagination in NodeJS and MongoDB. Check out the code I have written below: router.get("/PO_pagination", verify, async (req, res) => { console.log("req.query", req.query) try { let ...

Clicking on a JQuery dropdown menu will always result in it staying open

After creating a dropdown menu click, I noticed some strange behavior. When I click the dropdown button, the menu appears as expected. However, if I move my cursor away without clicking the button again, the dropdown menu disappears and behaves like a hove ...

jQuery can bring life to pseudo elements through animation

Currently, I am utilizing a:after, and it includes right: Ypx. I am interested in employing the animate method within jQuery to transition the element (a:after) from Ypx to Zpx. Is there a way to achieve this? Here is an example: [link-text][after] [lin ...

Is there a way to initiate an AJAX post request with the Authorization header for the initial request using Windows Authentication?

I'm working on a web application that has a video page and a Web API for logging purposes. The events are triggered using an ajax post request: function logAction(actionToLog) { $.ajax({ type: 'POST', url: "/api/v/" + cu ...

Occasionally, a loading gif appears after a vanilla JS/AJAX call, but the output

While using AJAX to retrieve JSON data containing information on the next steps, I am implementing a CSS class hide/show to toggle images/wrapper and loading .png image. However, even after toggling show/hide on the image, updating the image src, and addi ...

Creating Interactive Image Thumbnails with jQuery Dialog in ASP.NET MVC 4

Trying to implement a small functionality using jQuery and ASP.NET MVC 4, I encountered a problem. The issue lies with a list of thumbnails that represent products in my application: <ul class="thumbnails"> @foreach (var thumbnail i ...

Submitting a set of values in one request via POST with ajax to PHP

My goal is to pass multiple parameters through the POST method using AJAX in my PHP file. This will allow me to query a MySQL database based on the values received. In the HTML file, I have set up a dropdown menu and a text input field: <div class="dr ...

Exploring the OAuth 2.0 integration with OpenID Connect, Loopback, and Keycloak

I'm having trouble establishing a connection to Keycloak from Loopback. I've been experimenting with the keycloak-connect library available at: https://github.com/keycloak/keycloak-nodejs-connect This snippet shows my current implementation in ...

Parse a string in the format of "1-10" to extract the numbers and generate an array containing the sequence of numbers within the range

Looking to convert a string in the format "1-10" into an array containing the numbers within that range. Display the array on the screen using a for loop. For example, if "1-5" is provided, the resulting array should be: {1, 2, 3, 4, 5} Create a workflow ...

Developing a table with JavaScript by parsing JSON data

Starting off, I am relatively new to working with JavaScript. Recently, I attempted to generate a table using data from a JSON file. After researching and following some tutorials, I successfully displayed the table on a web browser. However, I noticed tha ...

What is the best way to highlight selected navigation links?

Recently, I implemented a fixed navigation bar with relevant links on a website. The navbar includes a jquery script for smooth scrolling when clicked. However, I am struggling to add a selected class to the clicked link. Despite trying various solutions f ...

Validation in Ajax Response

When receiving an object from my API call, I want to perform error checking before displaying the JSON data in my view. function response(oResponse) { if (oResponse && oResponse != null && typeof oResponse === "object" && oResponse.response ...

How can the text content within a tag be divided into multiple tags based on a specific maximum height for each tag?

If you have a block of HTML and you want to ensure that no single element exceeds a certain height, how would you go about splitting the element into multiple smaller elements? Keep in mind that the window width may affect this solution, so let's assu ...

Tips on retrieving a result from mongoose's findOne() function

I created a custom function using the findOne() method in Mongoose and now I need to use the result for another function. How can this be achieved? Thank you! module.exports.retrieveDeal = function(dealRequest){ Deal.findOne({name:dealRequest},functi ...

Dynamic Drop Down Menu with PHP and AJAX loading data from a JSON

Struggling to establish a connection between two drop-down menus using AJAX with data in JSON format. Despite multiple attempts, the code only displays empty drop-downs for both departments and projects. Unsure of where the mistake lies. Here is the code ...

Transitioning the height of a Vue component when switching routes

I've been struggling to implement a transition slide effect on my hero section. The height of the hero is set to 100vh on the homepage and half of that on other pages. Despite trying various methods, I haven't been able to get it working properly ...

Can anyone recommend a speedy sorting algorithm for an extensive list of objects in JavaScript?

Struggling to organize a large array of 2000 elements in ReactJS using JavaScript. The array includes: data = [ { index: 0, id: "404449", product_name: "ette", brand_name: "Dyrberg/Kern", base_pri ...

"Discover the steps to seamlessly integrating Snappuzzle with jQuery on your

I am a beginner when it comes to javascript and jquery, and I recently came across the snappuzzle plugin which caught my interest. After visiting snappuzzle plugin, I decided to download and link jQuery, jQuery UI, and the snappuzle.js in my HTML file. I a ...

Choosing Issues

My selectpicker is displaying data outside the dropdown menu before making a selection. The data appears both inside and outside of the dropdown. Can someone please help me identify the issue and guide me on how to fix it? <select class="selectpick ...

Determining the aspect ratio of an image

When trying to append an image to a div, I use the following code segment: $thisComp.find('.DummyImage').attr("src", this.imageUrl); Following this, I make an ajax call to retrieve the aspect ratio of the image: $.ajax(this.imageUrl).done( ...