Tips for extracting the menu key from a JSON object using AngularJS

Is there a way to access the "menu1" and "menu2" fields in AngularJS from the following JSON data?

{
"menu1": [
   {
     "item": "1",
     "Auth": "content/articleList",
   },
   {
     "item": "2",
     "Auth": "content/articleList",
   }],
 "menu2": [
   {
     "item": "3",
     "Auth": "publish/cacheSetting",
   },
   {
     "item": "4",
     "Auth": "publish/juggleList",
   }]
}

Answer №1

To achieve this, follow the example:

<div ng-repeat="(index, list) in tasks">
  {{ index }}
  <div ng-repeat="item in list">
    {{ item.task }} : {{ item.status }}
  </div>
</div>

Answer №2

If you have a Service that needs to be accessed in a Controller, you can follow these steps to load JSON data in the service and then use it from the Controller.

App.factory("MenuService", [ '$http', function($http) {
    return {
        getMenus: function() {
            return $http.get( '/menuService' );
        }
    }
}]);


App.controller("SomeController", ['$scope', 'MenuService', function($scope,MenuService) {
    $scope.doSomething = function() {
        MenuService.getMenus().success( result ) {
            $scope.menu1 = result.menu1;
            $scope.menu2 = result.menu2;
            // Perform actions with menu1 and menu2
        }
    }
}]);

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

"Revolutionize real-time data updates with Node.js, Redis, and Socket

Greetings! I am currently working on a project for my school that involves creating a "Twitter clone." My goal is to incorporate a publish subscribe pattern in order to facilitate real-time updates. One key feature users will have access to is the abili ...

Is it possible to navigate between jQuery EditInPlace fields using the Tab key?

Seeking advice on implementing tab functionality for a page with multiple jquery EditInPlace fields. The goal is to allow users to navigate between fields by pressing the tab key. Currently using the 'jquery-in-place-editor' plugin available at: ...

Ways to navigate to a different page while displaying an alert message?

Desperately seeking assistance with redirecting to another page and then triggering an alert("HELLO") once the new page is loaded. I have attempted the following approach: $.load(path, function() { alert.log("HELLO"); }); But using window.location o ...

The application logs are not displayed on the Pm2 dashboard

My node.js APIs are running on pm2 and I'm monitoring them using the pm2 dashboard. When I access the APIs through ssh, I can view the application logs by running the command: pm2 logs However, I'm facing an issue where I cannot view these logs ...

Tips for incorporating the multiply times async function into mocha tests

I am attempting to utilize the async function foo multiple times in my mocha tests. Here is how I have structured it: describe('This test', () => { const foo = async () => { const wrapper = mount(Component); const button ...

Does the useState hook have any connection to hoisting in React?

I am relatively new to React.js and JavaScript, currently working on a project where I need the ability to manually update my components as needed, due to limitations with a third-party library. After doing some research, I came across a pattern on the of ...

"Error message: The server tag within the OnClientClick attribute is not properly formed

In the HTML code, there is the OnClientClick attribute set to evaluate if IsActive is true before triggering a confirmation message for removing the control from Brand-Mappings. Unfortunately, this is currently causing a server tag not formed error. Any a ...

Using PHP to retrieve JSON data with YQL

Having trouble extracting the required data from a JSON stored inside a PHP variable. I'm not yet an expert in this type of data structure... Does anyone know how to make it work? I need to loop through the results, then locate each contact to retri ...

Guide on converting a JSON object into a TypeScript Object

I'm currently having issues converting my JSON Object into a TypeScript class with matching attributes. Can someone help me identify what I'm doing wrong? Employee Class export class Employee{ firstname: string; lastname: string; bi ...

The Angular Google Maps Module fails to initialize

After updating angular-google-maps to version 2.0.1 via bower and adding the required dependencies (bluebird, jquery, loadash), I noticed that my app works fine when I comment out google-maps. This suggests that the issue lies with angular-google-maps. He ...

Refreshing the MarkerCluster following an AJAX request

My current challenge involves an AJAX function that retrieves posts based on users with a specific role. While the query itself works fine, I am encountering an issue with refreshing the markers on Google Maps after the AJAX request is complete and the pos ...

Shifting hues with every upward and downward movement

I am experiencing a small issue with this JS code... -I have multiple divs that are changing automatically in rows as they move randomly... I want to change the color of the div moving up to green. And for the div moving down, I want to change the colo ...

The event bus I'm using isn't functioning properly within the axios interceptor, yet it operates smoothly in all my Vue components

Currently, I am utilizing VueJs and mitt for the eventBus. The mitt is globally loaded and functioning correctly as shown below: main.js const emitter = mitt(); const app = createApp(App) app.config.globalProperties.emitter = emitter I am able to call t ...

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. ...

Combining NodeJs with Mysql for multiple queries using a chained method

Hey everyone, I'm struggling with running mysql queries repeatedly in my Node.js application. I need to shape the second query based on the results of the first one. The code example I have below is not working as expected. Can anyone provide guidance ...

Contrast between PHP and JavaScript output texts

Hey everyone, I'm dealing with a bit of an awkward situation here. I am trying to return a string variable from PHP to JavaScript and use it for a simple comparison in my code. However, the results are not turning out as expected. Initially, I send a ...

What is the proper way to invoke a method within the same class, Class A?

I'm facing an issue where I need to call the method getData() inside my AJAX function again if a 401 status occurs and the counter is less than or equal to 1. However, for some reason, the method is not being called in that particular scenario. How ca ...

Apply the "ng-class" attribute to the parent of the chosen element

Another question arises in relation to the usage of ng-class... How can we dynamically add a class to the <ul> element when a <button> within its <li> is clicked? Check out the demo here Here is the HTML code snippet: <div ng-app=" ...

Yajl::ParseError: error in parsing: unrecognized character found in JSON data

Encountering an error while parsing with YAJL Ruby: 2.0.0-p0 :048 > Yajl::Parser.parse "#{resp.body}" Yajl::ParseError: lexical error: invalid char in json text. {"id"=>2126244, "name"=>"bootstrap", ...

How can the '!!user' syntax be utilized? What outcome does this code snippet produce?

I am looking to implement an angular route guard in my application. I came across this code snippet but I am confused about the line where user is mapped to !!user. Can someone explain the purpose of map(user => !!user) in this context? canActivate( ...