Is there a way to change the object properties displayed in ng-repeat from the controller?

With AngularJS, I've implemented an ng-repeat to display object properties. My goal is to access root.TooltipText in the controller.

Below is the HTML code snippet:

  <div id="root">
    <div ng-repeat="root in rootresults">
      <button type="button" class="btn btn-primary" ng-click="showpagetwo(root.Title, root.ID)" ng-if="root.Location == null">{{root.Title}}
        <span class="tooltiptextsmall tooltip-rightsmall" ng-if="root.TooltipSize =='Small'">{{root.TooltipText}}</span>
        <span class="tooltiptextnormal tooltip-rightnormal" ng-if="root.TooltipSize =='Normal'">{{root.TooltipText}}</span>
      </button>
    </div>
  </div>

And here is my controller implementation:

var app = angular.module('wizardApp', []);
app.controller('MainCtrl', function($scope, $http, $q){
  $(document).ready(function() {
    $scope.getRootList();
  });

  $scope.prepContext = function(url,listname,query){
    var path = url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query;
    return path;
  }

  $scope.getRootList = function() {
    rootList = $http({
      method: 'GET',
      url: this.prepContext(siteOrigin+"/divisions/testing","SupportList","?$orderBy=Title&$filter=RootItem eq 'Yes'"),
      headers: {
        "Accept": "application/json; odata=verbose"
      }
    }).then(function(data) {
      //$("#articleSection").fadeIn(2000);
      console.log(data.data.d.results);
      $scope.rootresults = data.data.d.results;
    });
  };
});

When logging data.data.d.results, it shows:

{
  "0":  {
    "Title": "Test1",
    "TooltipText": "Test1",
    "TooltipSize": "Small"
    },
  "1":  {
    "Title": "Test2",
    "TooltipText": "Test2",
    "TooltipSize": "Small"
    },
  ...
}

Is there a way to access object properties in the controller?

Answer №1

Once you've adjusted the results, everything should function properly as long as your

console.log(data.data.d.results);
is returning the correct data.

However, don't forget to also update

ng-if="root.Location == null"

to

ng-if="!root.Location"

The reason for this change is that root.Location is appearing as undefined, which is not equivalent to null.

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

Dragging Three.js points

In need of help with generating a large number of draggable objects that are limited to a plane form such as rectangles or circles. Initially, I used simple CircleGeometries placed inside another geometry (plane) for easy dragging, but performance suffered ...

AngularJS resource state description

Encountering a challenge with my AngularJS application communicating with a REST API. The issue lies in the API returning a status code along with a status description such as HTTP/1.1 417 Invalid quantity. In the past, when using jQuery AJAX, the jqXHR ob ...

"Exploring ways to implement validation for multiple email addresses in a textarea using JQuery or JavaScript, while allowing the addresses to be separated by semicol

NOTE: Each email ID must be unique. An empty string value is allowed to be added. Email IDs should be separated by semicolons and commas. Basic validation of email IDs is necessary for entry. [![ $("#d-notification").focusout(function () { var ...

Looping through a collection of items within an object

Currently, I am working on navigating through a list of objects that contain another list of objects. Displayed in the image below is an example of how an object looks and how the forEach function operates. This is a snippet of my code : myApp.controlle ...

Unable to incorporate an external JavaScript file via a static URL

I'm attempting to link an external javascript file using a static URL, like this: <script type="text/javascript" src="{{ url_for('static/js', filename='test.js') }}"></script> However, I am encountering the following ...

What are the steps to create a basic chrome extension that functions as a countdown clock?

I am a beginner in the world of coding and I am currently working on creating a chrome extension that serves as a timer. My goal is to include the timer within the HTML popup file, allowing users to customize the settings themselves. Do you have any advice ...

What might be causing the 500 internal error in jquery.min?

Hello, I am encountering a 500 internal server error when I click this button that performs the following action: $(".btn-email").on('click', function() { swal('Waiting','Please wait, sending email now','info'); ...

Is there a way to dynamically access BEM-style selectors using CSS modules?

For instance, I have this specific selector in my App.module.css file: .Column--active I want to access this selector from the App.js file in React using CSS modules. After importing all selectors from the CSS file as import styles from './App. ...

JS - Add a key to corresponding values in arrays and objects

I'm looking to populate objects in array1 with key values from other objects in array2. This involves matching corresponding values in both arrays and pushing the correct key. let array1 = [ { "Ref": "28189-060-B", "Otherkey": "Whatever" ...

ng-repeat not recognizing filter

I currently have an array of contacts with objects structured as follows: {"active":false,"lastName":"fdg","name":"riman","table":3}.... Although I am able to view all the items, I am encountering an issue with the filter not functioning as expected. Her ...

Is there a way to make images load only when the navigation buttons are clicked in a scrollable (jquery tools) rather than loading all images at once?

I came across this great demo tutorial that I'm currently following: The issue with the tutorial is that it loads all the images at once, which significantly impacts performance. My goal is to have it load a set of images each time you click the arro ...

Is there a way to retrieve the ID from a span and convert it into a string format?

let wordSpan = '<span class="we w_o_r_d_s" id="we" contenteditable="false">we</span>' console.log(wordSpan.id); console.log(wordSpan.attr('id')); console.log(wordSpan.getAttribute('id')); let newDiv = document.c ...

Unable to bind `this` using `call` method is not functioning as expected

Attempting to modify the Express app's .set function to be case-insensitive. For example, app.set('PORT',80); app.set('port'); // => undefined; aiming for it to return 80 Essentially, it's just a function that changes the ...

The function $q.all() results in an array containing values that are not defined

I am currently working on a project that involves fetching data from the backend using 3 different functions. Below is the code snippet from my controller.js file: $scope.getList1 = function () { service.getList1(constants.getUrl1).then( funct ...

What are the steps to effectively utilize the static folder in Django for organizing CSS and JavaScript files?

I'm completely new to the Django framework. I managed to create a simple welcome page, but now I'm struggling to include a CSS file in my project. Whenever I try to apply the CSS file, I encounter an error saying "NetworkError: 404 NOT FOUND - / ...

Manipulate CSS classes in an ng-repeat list using AngularJS

Dear colleagues, let's take a look at this clear example. [...document.querySelectorAll('.li-example')].forEach((s, i, arr) => { s.addEventListener('click', function() { [...document.querySelectorAll('.li-example&a ...

What is the method for transforming an array object into an object?

How can I assign the values of an array object called hello to a constant called answer, changing the key value in the process? I've considered using Object.entries but couldn't quite get it right. Is there a way to achieve this? Here is my cod ...

Redirecting from HTTP to HTTPS with node.js/Express

Are there steps I can take to modify my web application to operate on HTTPS instead of HTTP using node.js/express? I require it to run on HTTPS due to the use of geolocation, which Chrome no longer supports unless served from a secure context like HTTPS. ...

Eliminating the   character from a division element

I am currently working on a logic to eliminate any   elements within a div element. I attempted to replace the   element using the following code: (div.html().replace(/^\s*&nbsp;/m, '')); However, the issue I am facing is that ...

Converting Rails data into JSON objects using hashing techniques

I'm currently working on a Rails query that looks like this: @c = RealEstateAgentAssignmentStatus.joins(:real_estate_agent_assignments =>:loan_application) .group("real_estate_agent_assignment_statuses.assignment_status").select("real_estate_a ...