jsonangularhardcoded

How to read the hard coded json data in controller file and display its value


I am looking for a way to hardcode the json data in controller file and read the value and display it.

 var params = [
                    {
                            "id":1,
                            "title":"BA",
                            "name":"Kate"       
                    }
              ]

This is the json data I have in controller file. How can i read the data and display it in console.


Solution

  • if this is always going to be a single item, why are you making it an array? You could just do the following:

    let params = {
      "id":1,
      "title":"BA",
      "name":"Kate"     
    };
    

    Then access the data like this:

    params.id
    params.title
    params.name