Ways to navigate to specific app information when tapping on the app

I am dealing with Json data

models: Array<Model> = [
    {
      name: 'kanban',
      version: '1',
      processes: [
        {
          name: 'kanban',
          version: '1',
          descrption: 'kanabn'
        },
        {
          name: 'kanban 2',
          version: '2',
          descrption: 'kanban 2'
        }
      ]
    },
    {
      name: 'gibier',
      version: '1',
      processes: [
        {
          name: 'gibier',
          version: '1',
          descrption: 'gibier'
        },
        {
          name: 'gibier 2',
          version: '2',
          descrption: 'gibier 2'
        }
      ]
    }
  ];

Using this, I have designed a page like below:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card" *ngFor="let app of models">
  <div class="card-body">
    <h2>{{app.name}}</h2>
    <h4>{{app.version}}</h4>
  </div>
</div>

I have two cards displayed on the page.

When clicking on a card, I expect to see details specific to that appName.

** App.module.Ts **

  {
    path: 'applicationDashboard',
    component: ApplicationDashboardComponent
  }, {
    path: 'applicationDashboard/:id',
    component: ApplicationDetailComponent
  },
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="row" *ngFor="let apps of models">
  <div class="col-4" *ngFor="let process of apps.processes">
    <div class="card">
      <div class="card-body">
        <div class="fadein">
          <div class="item-box" ng-style="{'background-image': 'url(\'' + config.contextRoot + '/app/rest/models/' + process.id + '/thumbnail?version=' + imageVersion + '\')'}" (click)="showProcessDetails(process);" style="background-image: url(&quot;/activiti-app/app/rest/models/f6b21c92-81bb-4fc9-990f-852729e131f1/thumbnail?version=1533200931200&quot;);">
            <div class="actions">
              <span class="badge badge-secondary">v{{process.version}}</span>
            </div>
            <div class="details">
              <h3 class="truncate ng-binding" [title]="">
                {{process.name}}
              </h3>
            </div>
          </div>
        </div>
      </div>
      <div class="card-footer">
      </div>
    </div>
  </div>
</div>

import {
  Component,
  OnInit
} from '@angular/core';
import {
  Model
} from '../../model';
import {
  ModelService
} from '../../model.service';
import {
  Route,
  ActivatedRoute
} from '@angular/router';

@Component({
  selector: 'app-application-detail',
  templateUrl: './application-detail.component.html',
  styleUrls: ['./application-detail.component.css']
})
export class ApplicationDetailComponent implements OnInit {
  name;
  model: any;
  models: Array < Model > = [];
  constructor(private modelservice: ModelService, private _route: ActivatedRoute) {
    this.models = modelservice.getModel();
    this.name = this._route.snapshot.paramMap.get('id');
    console.log(this.name);
  }

  ngOnInit() {
    this.model = this.models;
    console.log(this.model);
  }
  showProcessDetails(process) {
    console.log('keerthi', this.models.find(x => x.processes === process));
  }

}

I have implemented routing and data display in the above code.

The issue faced is:

Even though I can navigate to the correct page, all 4 processes in my json data are being displayed without considering the specific App.

Can someone provide assistance?

Thank you in advance!

Answer №1

Simply use (click) instead of ng-click, as it is the AngularJS syntax.

(click)="showProcessDetails(process);

Answer №2

I decided to take the name from the ID that I am routing to in my Angular application:

this.name = this._route.snapshot.paramMap.get('id');

Next, I iterated through the model data and retrieved the details based on the comparison with this.name

In the HTML template, I used

*ngFor="let apps of model.processes"

*ngIf="apps.name ==name"

import {
  Component,
  OnInit
} from '@angular/core';
import {
  Model
} from '../../model';
import {
  ModelService
} from '../../model.service';
import {
  Route,
  ActivatedRoute,
  Router
} from '@angular/router';

@Component({
  selector: 'app-application-detail',
  templateUrl: './application-detail.component.html',
  styleUrls: ['./application-detail.component.css']
})
export class ApplicationDetailComponent implements OnInit {
  name;
  model: any;
  models: Array < Model > = [];
  constructor(private modelservice: ModelService, private _route: ActivatedRoute, private router: Router) {
    this.name = this._route.snapshot.paramMap.get('id');
    console.log('name', this.name);
  }

  ngOnInit() {
    this.models = this.modelservice.getModel();
    for (let i = 0; i < this.models.length; i++) {
      if (this.name === this.models[i].name) {
        this.model = this.models[i];
        console.log('model:', this.model);
      }
    }
  }
  showProcessDetails(process) {
    this.router.navigate(['/process', process.name]);
  }

}
<div class="container-fluid">
  <div>
    <nav class="navbar subheader">
      <h2>App definition Details :{{name}} </h2>
    </nav>
  </div>
  <div class="jumbotron">
    <div class="col-4 preview-wrapper justify-content-start" *ngFor="let apps of model.processes">
      <div class="card" *ngIf="apps.name ==name">
        <div class="card-body app theme-1">
          <div class="app-content">
            <h3>{{apps.name}}</h3>
            <p>{{apps.details}}</p>
          </div>
          <div class="backdrop">
            <i ng-show="!app.appDefinition.icon" class="icon icon-choice ng-hide"></i>
            <i ng-show="app.appDefinition.icon" class="fa fa-asterisk" aria-hidden="true"></i>
          </div>
          <div class="logo">
            <i ng-show="!app.appDefinition.icon" class="icon icon-choice ng-hide"></i>
            <i ng-show="app.appDefinition.icon" class="fa fa-asterisk" aria-hidden="true"></i>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-4" *ngFor="let process of model.processes">
        <div class="card">
          <div class="card-body">
            <div class="fadein">
              <div class="item-box" (click)="showProcessDetails(process);">
                <div class="actions">
                  <span class="badge badge-secondary">v{{process.version}}</span>
                </div>
                <div class="details">
                  <h3 class="truncate">
                    {{process.name}}
                  </h3>
                </div>
              </div>
            </div>
          </div>
          <div class="card-footer">
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

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

Determining the Suitability of an Angular2 Module for Importing into a Shared Module

Is there a specific method to determine if a module qualifies as a provider or if it exports other modules that act as providers; in order to be considered for inclusion in the "shared" module? According to angular.io: "The SharedModule should not have p ...

Tips for changing a "raw" DOM Event into a React SyntheticEvent

Currently, I am working with two separate libraries. The first library emits "raw" DOM events (lib.dom.d.ts), while the other library consumes React.SyntheticEvents. I am seeking advice on the most efficient method to transform the raw event into a Synthe ...

Angular6: Generating a dynamic list of radio buttons with unique identifiers

I have a challenge in creating a dynamic list of radio buttons from a JSON array. While I can successfully do that, the specific requirement is to assign a unique ID to each radio button generated. The structure of my JSON data is as follows: this.employe ...

Angular4 ChromeDriver Selenium Protractor

I am facing an issue while trying to run 'ng e2e'. The error message I encounter is as follows: WebDriverError: unknown error: cannot find Chrome binary I am using Protractor which is pre-installed with Angular CLI. Despite reinstalling ChromeD ...

The raw password value must be provided and cannot be left blank

I am currently learning Java Springboot and working on creating a todo app with React (TypeScript) and Springboot. As I attempt to signup, an error occurs stating "rawPassword cannot be null" from Springboot. My frontend is running on localhost:3000 and b ...

The dance of Angular's life-cycle hooks

Recently, I created a sketch to visually represent the flow of a component's life-cycle. I used the tool sketch.io for this project. After thoroughly reading through the documentation on life-cycle hooks, I finalized my sketch. Do you think this ...

The CSS for the ng2-eonasdan-datetimepicker is not displaying correctly

I recently added the ng2-eonasdan-datetimepicker to my project, but I am having issues with the CSS not being applied correctly. Here is what it currently looks like compared to what it should look like... https://i.stack.imgur.com/U6dXN.jpg In my compon ...

Bootstrap is unable to consistently align elements on a single page

Utilizing bootstrap 4 within my page, I structure it as follows: <div class="container"> <div class="row"> <div class="col-md-12"> <div class="col-md-6"> <label>"GO"</label> ...

Utilizing Regular Expressions in Angular 4 by Referencing Patterns Stored in an Object

I'm facing an issue where my code is functional, but I keep encountering a Tslint error that's proving difficult to resolve. This particular configuration worked fine with Angular 1, but now I'm in the process of migrating the application to ...

How to dynamically set the APP_BASE_HREF in Angular CLI

My dilemma lies in dynamically setting either the <base href="" /> tag located in the index.html, or dynamically setting the APP_BASE_HREF in the app.module.ts. I am faced with uncertainty when it comes to modifying anything within the static text o ...

Guide on storing geolocation information in an array on Google Firebase Realtime Database using Angular HttpClient

I have been working on developing an innovative Android geolocation tracking app using Ionic with the assistance of the Cordova Geolocation plugin. The tracking feature has been successfully implemented thus far. However, I am currently facing challenges w ...

Encountering a problem with SVG integration in Gatsby with Typescript

In my current project, I am experimenting with using SVG in a Typescript page in Gatsby. To achieve this, I decided to utilize the Gatsby plugin called . //gatsby-config.js { resolve: "gatsby-plugin-react-svg", options: { ...

Unable to display the attributes of an object using console.log

I am attempting to log the properties of an object in TypeScript, but I am encountering issues. setTitleAndBody(result: { title: String; body: String; }) { console.log(result) console.log(result.title) } What's interesting is that if I only l ...

Is it possible to overlook TypeScript errors when compiling with Angular 2 AoT?

My application is experiencing numerous TypeScript errors, even though it runs correctly. I recently migrated a JavaScript app to TypeScript and am struggling to resolve all the type-related issues. In order to proceed with development, I have configured m ...

Expanding the npm packages available on the Azure DevOps Feed

My current project utilizes Angular 2.4 and includes a .npmrc file configured to use an internal registry. The build pipeline I have set up is throwing the following error: No matching version found for yargs@^3.32.0. In most cases you or one of your dep ...

My goal is to eliminate the console error message "@ Angular: GET http://localhost:4200/assets/i18n/1/fr.json 404 (Not Found)" related to missing file

Is there a way to prevent the "GET http://localhost:4200/assets/i18n/1/fr.json 404 (Not Found)" error from appearing in both the console and network of the browser while using Angular? I need a solution for this.custom.translate.loader.ts****** return Obse ...

Troubleshooting Angular4 and TypeScript Compile Error TS2453: A Comprehensive

I'm facing an issue in my Angular4 project build process which I find quite perplexing. The error seems to be related to the import of certain components such as Response, Headers, and Http from @angular. Whenever I attempt to build my project, it thr ...

Resetting the value of a radio button input option to null using Angular2 ngModel

In my Angular2 application, I am attempting to implement radio button inputs using ngModel and value. The goal is to have three options: true, false, and null. However, I am struggling to assign a value of null to one of the inputs. Ideally, when nothing ...

What distinguishes Angular directives as classes rather than functions?

When using Ng directives within HTML tags (view), they appear to resemble functions that are called upon rather than instances of a class. It almost feels like they could be static methods that can be invoked without an instance of a class. Comin ...

Testing the throwing of errors when running Karma by utilizing sinon.spy on global functions like parseInt

I'm currently facing an issue with monitoring the usage of parseInt within my function. This is a Proof of Concept for integrating TypeScript into our company's workflow. I've tried following two different tutorials on testing Sinon, but no ...