AngularJS item

I am a beginner in AngularJS and need help with printing object attributes in AngularJS controller.

  @RequestMapping(value = "/rest/getById",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @RolesAllowed(AuthoritiesConstants.ADMIN)
    public ChartConfigs findOne(Integer id) {
         return chartConfigService.getOne(1);

    }

This is the AngularJS service:

    myappApp.factory('ChartConfigService', function ($http) {
 return {
    findOne: function() {
        var promise = $http.get('app/rest/chartConfigs/getById').then(function (response) {
            return response.data;
        });
        return promise;
    }
   }
  });

This is the AngularJS controller:

  myappApp.controller('ChartConfigController', function ($scope, ChartConfigService) {
        $scope.message = ChartConfigService.findOne();
        var obj = ChartConfigService.findOne();
            console.log(obj.type);

  });

ChartConfig Domain:

Package com.innvo.domain;

    @Entity
    @Table(name = "T_CHART_CONFIGS")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    public class ChartConfigs {


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id")
    private Integer id;

    @Column(name = "category")
    private String category;

    @Column(name = "type")
    private String type;



    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
 }

Answer №1

If you are dealing with the scenario where obj is also a promise, you will need to handle it like this:

ChartConfigService.findOne().then(function(obj) {
    console.log(obj.type);
});

When you try to access obj.type, it will be undefined because the property type does not actually exist on the promise object.

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

At random intervals, a ReferenceError is triggered stating that Vue is not defined

While working on an application that uses templates rendered by Apache Velocity, I encountered the error "Uncaught ReferenceError: Vue is not defined" when trying to incorporate vue.js components. Oddly enough, this error is not consistent - it occurs most ...

Issues arise when trying to integrate external JavaScript files into a Vue application

I am facing an issue with including external JS files in my HTML document. The website requires these files to function properly. What I have attempted: In the main.js file, I tried adding these imports: import '../../assets/js/jquery-3.5.1.min&apos ...

How can I retrieve the latest state of the Redux store in getServerSideProps in Next.js?

I am attempting to retrieve the most up-to-date redux state in getServerSideProps like so: export const getServerSideProps = async (ctx) => { const state = store.getState(); console.log(state.name); return { props: { login: false } }; }; H ...

Encountering an undefined error in Angular while running Karma-Jasmine tests

I am struggling with testing using Karma-jasmine to run my tests as I keep encountering errors. Here is a snippet from my karma.conf.js file: files: [ 'test/*Spec.js', 'app/js/*.js' ], When I run the test, I receive the following ...

Retrieve latitude and longitude values from a string of varying length

Is there a way to extract latitude and longitude values from a string that contains multiple pairs, such as the following: var data = "(-20.210696507479017, -70.14000177383423),(-20.21202551027535, -70.14246940612793),(-20.21385790460967, -70.140666961669 ...

Ways to ensure a button is ready to be clicked

For my beginner chrome extension project, I am facing a specific situation that I need help with. Imagine a scenario where I have a website with a search button. When the button is clicked, two possibilities can arise: A search result appears with a butt ...

Capturing the value of a child element using an Angular directive

When I include scope: {finishcallback: "&"} in my directive, the binding of values with $scope.minutes = 1 to ng-bind="minutes" stops working. I am currently working on creating a countdown timer using Angular directives. However, I am facin ...

The failover process for PayPal involves seamless transitions to backup systems in the

I am currently assisting a client with a unique architecture setup: Back End Running on Java Server Front End Powered by Proxy (Node JS + Express application) For security reasons, all requests made to the server must pass through the Proxy. We ar ...

Using ng-repeat on a select element is replacing the original content

I'm struggling with the following code snippet: <select> <div class="arrow-up"></div> <option data-ng-repeat="x in y">{{x}}</option> </select> the resulting output doesn't show the arrow div like this ...

The issue I am facing is that when I click on a checkbox, only one of them seems to respond

When I click the button, only the first checkbox event is being checked while the rest of them are not. Can someone please provide some guidance on how to fix this issue? $("#cascadeChange").click(function() { //alert("Clicked"); ...

The process of loading an image becomes stuck once the submit button is pressed

I have multiple JSP pages where I use an ajax call to submit data. On these pages, I am able to display a loading image before the ajax call and hide it once the call is complete, which works perfectly. $(document).ajaxComplete(function() { $("#loadi ...

Tips for recognizing when Vuetify's v-autocomplete has reached the final scrolled item

I am working with a Vuetify v-autocomplete component and I need to implement a feature where I can detect when the user reaches the last item while scrolling, in order to load more items without the user having to manually type for search: // component.vue ...

Storing data in an object or array using Node.js to improve caching efficiency

I'm attempting to store and retrieve information in a node CLI script using either an array or an object. My goal is to have a simple key-value setup where I can fetch usernames by using the ID as the key. The code snippet below shows my attempt, but ...

Ways to retrieve Payload following the Request url access

Currently utilizing Selenium with Python to conduct website testing, I successfully accessed the Request link and now aim to access the Payload. Below is an image displaying the process: view image description here driver = webdriver.Chrome(options=option) ...

Creating randomized sequences using JavaScript

One of my hobbies involves organizing an online ice hockey game league where teams from different conferences compete. It's important to me that every team gets an equal number of home and away matches throughout the season. To simplify this task, I&a ...

Trouble with Swiper carousel loading new slides

Currently, I am working on a project using Cordova and jQuery. I have implemented the Swiper library by idangero for handling slides. The problem arises when I add new slides and try to display them. Here is the relevant jQuery code snippet: if(row.pict ...

Initiate a series of tasks and await their completion using RxJS / Redux Observables

My app requires an initialisation action to be fired, followed by a series of other actions before triggering another action. I found a similar question on Stack Overflow However, when attempting this approach, only the initial APP_INIT action is executed ...

What is the best way to manage the back button functionality on pages that use templates?

I am currently developing a website using angularjs. The layout consists of two main sections: the menu and the content area. For instance This is an example page: /mainpage <div> <div id="menu"> <div ng-click="setTemplate('fi ...

The perplexing paradox of THREE.js line thickness

Upon reviewing the LineBasicMaterial THREE documentation, I came across a note stating that on Windows systems, the linewidth is automatically set to 1 and cannot be adjusted. Interestingly, there is a fascinating example on threejs.org utilizing the same ...

Issue: ENOENT error occurred during execution on Docker Container due to missing file or directory '/root/.aws/credentials'

click here for image description While the app runs normally locally, attempting to run it in a Docker container results in an error displayed on the screen. This is my Docker file: FROM node:14.0.0 WORKDIR /app ARG DATABASE_URL ARG AWS_REGION ARG CLIENT_ ...