Dynamically loading JSON content in an Angular application based on the user's selected item

I am utilizing a table that is populated through a REST request to

http://localhost:8080/Sprint002b/restpatent/
.

Upon clicking on an item within the table, which can be found in list-patents.htm, a separate container appears in patent-item.htm. This container contains a tab panel with 3 tabs and it should display all relevant information from the JSON file corresponding to the selected item.

Having referred to How can I pull data (JSON) from a clicked ng-repeat item to load a new, item specific page using $stateParams and ui-router?, I have successfully implemented the functionality provided. However, I am now uncertain about the next steps.

The tab panel loads upon clicking a ui-sref in the table to a ui-view below it, but currently only displays placeholder content. How can I populate the tab panel with data from the JSON file related to the clicked item? Apologies if this is unclear.

list-patents.htm

<table class="table table-bordered table-striped text-md-center">
  <thead class="thead-inverse">
    <tr>
      <td ng-click="patentAppOrder()" class="align-middle">Application No. </td>
      <td class="align-middle">Client Ref</td>
      <td class="align-middle">Cost to renew</td>
      <td class="align-middle">Basket</td>
      <td class="align-middle">Remove</td>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="x in patents">
      <td><a ui-sref="patents.list.item">{{x.applicationNumber}}</a></td>
      <td ng-bind="x.clientRef"></td>
      <td ng-bind="x.costToRenew">$</td>
      <td ng-bind="x.renewalDueDate"></td>
      <td>
        <button type="button" class="btn btn-danger" ng-click="remove(x.id)">Remove</button>
      </td>
    </tr>
  </tbody>
</table>
<div ui-view></div>

patent-item.htm

<div id="tabs">
  <ul>
    <li ng-repeat="tab in tabs" ng-class="{active:isActiveTab(tab.url)}" ng-click="onClickTab(tab)">{{tab.title}}</li>
    <!--applies active to the returned tab url -->
  </ul>
  <div id="mainView">
    <div class="row">
      <div ng-include="currentTab"></div>
    </div>
  </div>
</div>
<script type="text/ng-template" id="patent-info.htm">
  <div class="col-md-6 text-xs-center">
    <h2>Application Number: <!--data to be loaded--></h2>
    <table class="table table-striped">
      <tbody>
        <tr>
          <td class="font-weight-bold">Short Name</td>
          <td>
            <!--data to be loaded-->
          </td>
        </tr>
        <tr>
          <td class="font-weight-bold">Client Reference</td>
          <td>
            <!--data to be loaded-->
          </td>
        </tr>
        <tr>
          <td class="font-weight-bold">Applicant Name</td>
          <td>
            <!--data to be loaded-->
          </td>
        </tr>
        <tr>
          <td class="font-weight-bold">Application Number</td>
          <td>
            <!--data to be loaded-->
          </td>
        </tr>
        <tr>
          <td class="font-weight-bold">Publication Number</td>
          <td>
            <!--data to be loaded-->
          </td>
        </tr>
        <tr>
          <td class="font-weight-bold">Title</td>
          <td>
            <!--data to be loaded-->
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="col-md-6 text-xs-center">
    <!--data to be loaded-->
  </div>
</script>
<script type="text/ng-template" id="cost-analysis.htm">
  <!--data to be loaded-->
</script>
<script type="text/ng-template" id="renewal-history.htm">
  <!--data to be loaded-->
</script>

var app = angular.module('myApp', ['ngRoute', 'angularMoment', 'ui.router', "chart.js"]);

app.config(['$stateProvider', '$locationProvider', '$urlRouterProvider', function($stateProvider, $locationProvider, $urlRouterProvider) {

        $urlRouterProvider
          .when('', '/patents/list-patents')
          .when('/', '/patents/list-patents')
          .when('/patents', '/patents/list-patents')
          .when('/transactions', '/transactions/current-transactions')
          .otherwise('/patents/list-patents');

        $stateProvider
          .state("patents", {
            url: "/patents",
            templateUrl: "templates/patents/patent-nav.htm",
            controller: "patentCtrl"
          })
          .state("patents.list", {
            url: "/list-patents",
            templateUrl: "templates/patents/list/list-patents.htm",
            controller: "patentCtrl"
          })
          .state("patents.list.item", {
            url: "/patent-item",
            templateUrl: "templates/patents/list/patent-item.htm",
            controller: "patentCtrl"
          })


        app.controller('patentCtrl', ['$scope', '$http', 'patentTabFactory', 'loadPatents', '$stateParams', 'patentService', function($scope, $http, patentTabFactory, loadPatents, $stateParams, patentService) {

          patentService.items.then(function(patents) {

            $scope.items = patents.data;
            console.log($scope.patents);
            $scope.patents = patents.data[patentService.getPatentItem($scope.items, "aid", $stateParams.id)];

          });
        }]);

Answer â„–1

To send data using state, you can use the following method:

$state.go('patents', {
  'projectId': projectId,
  'otherdata': otherdata
});

Your routing configuration will be as follows:

$stateProvider
  .state("patents", {
    url: "/patents/:parentId/:otherdata",
    templateUrl: "templates/patents/patent-nav.htm",
    controller: "patentCtrl"
  })

In your next controller, you can retrieve the values like this:

var projectId = $state.params.projectId;
var otherdata = $state.params.otherdata;

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

The functionality of my website is currently experiencing difficulties when accessed through the Android UC Browser

My website, , is experiencing issues with product loading and the '+' button in the side menu not working on UC Browser. It works fine on other Android browsers like Chrome and Firefox, but I am confused as to why it is not functioning properly o ...

Photoswipe using identical source code, yet the output is malfunctioning

Having an issue with my code that refreshes the content of a ul element. Initially, it works fine by directly loading the ul content, but I am constantly creating new content every 10 seconds to provide users with fresh updates. Even though the source co ...

Separating buttons (two buttons switching on and off simultaneously) and displaying the corresponding button based on the data

My current project involves creating a registration page for specific courses. While I am able to display the information correctly, I am facing an issue with the ng-repeat function. The problem lies in all the Register buttons toggling incorrectly. Additi ...

Secure your Rails application by implementing CSRF protection for JSON requests

Looking for a solution to enable post/put/patch/delete requests from my android app to my Rails application, receiving JSON responses, while maintaining active CSRF protection on the server. In essence, I need a way to prevent forgery when communicating b ...

Exploring the best practices in a jQuery demo application

Hoping to find a jQuery sample app that showcases best practices such as: Retrying XMLHttpRequests in case of network issues Using XMLHttpRequest for login functionality Implementing a loading indicator with XMLHttpRequest Handling history with XMLHttpRe ...

Choosing a specific element within another element of the same type using JQuery

I've created a complex nested HTML structure shown below: <ul class="root"> <li>Foo 1 <label class="bar-class">bar</label> <ul> <li>Foo 2 <label class="bar-class">bar</label> ...

What steps should be taken to activate eslint caching?

I'm attempting to activate eslint caching by following the instructions in this section of the user guide The command I am using is npm run lint -- --cache=true, and the lint script simply executes a script that spawns esw (which itself runs eslint â ...

Retrieve information from a changing HTML table

I am working on a nodejs express project that features a Dynamic Table within my application. Users can add or remove rows and enter values into cells, but I am struggling to extract these values from the table without using jquery. My goal is to then inse ...

Exploring the differences between arrays and objects provided by users

I am working on a functionality that involves comparing user input with predefined usernames and passwords. Here is what I have so far: var sys = { users: [ {user: 'user1', pass: 'qwerty'}, {user: 'Ragnar&apos ...

What is the process for transferring image attributes to the server via a URL?

My data transmission process only involves sending data. Below is the data I send: export const cabin = { name: '001', maxCapacity: 2, regularPrice: 250, discount: 0, image: './cabins/cabin-001.jpg', description: ...

Issue with THREE.js: Object picking does not display the parent object name when an object is loaded using OBJMTLLoader

I successfully loaded an OBJ file along with MTL file textures using OBJMTLLoader. The code I used was borrowed from . The primary object, a man in a business suit with hair, hands, and shoes, is displayed correctly with all the textures applied, such as ...

Employing require.js, one can integrate a distinctive form of non-concatenated dat.gui source. This allows for the seamless

Excuse the SEO-friendly title, but I want to ensure that everyone can access the issue I'm currently working on. For those interested in customizing the appearance of dat.gui, you will need to download the source and include it using require.js follow ...

Troubleshooting scope evaluation in AngularJS within style tags on IE9 not functioning

My issue involves a div block with a style attribute that includes left:{{left}}px; and right:{{right}}px. Even though $scope.left and $scope.right are being updated, my item still doesn't move as expected. I have created a fiddle to demonstrate th ...

Tips for organizing dynamic table data following an append operation

Hey there! I'm currently working on a project involving sorting students after applying filters. Once the students have been filtered, I need to append classes and text to buttons as shown in the image below: https://i.stack.imgur.com/c9Mtm.png The HT ...

``There seems to be an issue with the functionality of Angular's $routeProvider

I'm currently facing an issue with my setup. I have a local angular front-end running on localhost using an Apache Server on Linux. When I try to access localhost, everything works fine and I can see my index.html. However, I have a link in the index. ...

Updating the information displayed in one section by selecting a button on the Google Maps infowindow located in a separate section

My webpage is divided into multiple divisions. One division contains a map using the Google Maps API with markers. When I click on a marker, an info window opens up. Now, I am attempting to place a button inside that info window which, when clicked, will ...

Unable to start initial Cucumber+javascript demonstration

I attempted to run the initial example provided in the official documentation found here. Using Windows 7x64 bit and node.js version 6.11 I ran the following commands but encountered the same outcome. * node_modules/cucumber/bin/cucumber.js autotests/c ...

Retrieve information from Django and pass it to the Vue template

I'm attempting to transfer information from Django into Vue template variables. views.py def index(request): myvar = 1 return render(request, 'index.html',{'myvar':myvar}) within index.html <span> {{ myvar }} </span& ...

Is it possible to verify an email address using a "Stealthy Form"?

I am exploring the use of HTML5's type="email" validation to develop a function for validating email addresses. My goal is to create a form and add an input that has its type set as email. By attempting to submit the form, I aim to determine whether ...

Incorporate action icons (such as edit and delete) into a table in React.js using material-ui

Within my existing table, I utilized a library known as react-bootstrap-table-next This library effectively displays data in a table format with values originating from a JSON response Now, my goal is to integrate an Action column that includes options f ...