Display only the selected view

Here is a snippet of the template I am working on:

       <tbody *ngFor='let list of lists'>
                <tr>
                    <td>{{ list.name }}</td>
                    <td>{{ list.location }}</td>
                    <td>{{ list.type_id }}</td>
                    <td>{{ list.gos_prinad_id }}</td>
                    <td>{{ list.disloc_country_id }}</td>
                    <td>{{ list.adm_terr_id }}</td>
                    <td><a (click)="toggleElement()">view</a></td>
                    <td>{{ list.lat }}</td>
                    <td>{{ list.lon }}</td>
                    <td>{{ list.alt }}</td>
                </tr>
                <tr [hidden]="hideElement" *ngFor="let new_var of list.hops">
                    <td>{{ new_var.hop_type }}</td>
                    <td>{{ new_var.id_sl_hop }}</td>
                    <td>{{ new_var.hop_text }}</td>
                </tr>
        </tbody>

Also, I have a function called toogleElement() to toggle the display of additional data:

toggleElement(){
        if(this.hideElement) {
            this.hideElement = false;
        }else{
            this.hideElement = true;
        }

Currently, a new form opens up every time I click on view.

<tr [hidden]="hideElement" *ngFor="let new_var of list.hops">
                    <td>{{ new_var.hop_type }}</td>
                    <td>{{ new_var.id_sl_hop }}</td>
                    <td>{{ new_var.hop_text }}</td>
                </tr>
        </tbody>

However, I wish for only one form to open at a time, rather than for each row.

Apologies for any language errors in my message.

Answer №1

toggleItem(items){
    items.isVisible= !items.isVisible;
}
<tbody>
    <template ngFor let-items [ngForOf]="items">
        <tr>
            <td>{{ items.name }}</td>
            <td>{{ items.location }}</td>
            <td>{{ items.type_id }}</td>
            <td>{{ items.gos_prinad_id }}</td>
            <td>{{ items.disloc_country_id }}</td>
            <td>{{ items.adm_terr_id }}</td>
            <td><a (click)="toggleItem(items)">смотр.</a></td>
            <td>{{ items.lat }}</td>
            <td>{{ items.lon }}</td>
            <td>{{ items.alt }}</td>
        </tr>
        <tr [hidden]="!items.isVisible" *ngFor="let new_var of items.hops">
            <td>{{ new_var.hop_type }}</td>
            <td>{{ new_var.id_sl_hop }}</td>
            <td>{{ new_var.hop_text }}</td>
        </tr>
    </template>
</tbody>

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

Generating Angular components dynamically in batch

I have a collection of diverse data objects: const arr = [ {type: 'CustomA', id: 1, label: 'foo'}, {type: 'CustomB', src: './images/some.jpg'} {type: 'CustomX', firstName: 'Bob', secondNa ...

Resolving DOMException issue in Google Chrome: A Step-by-Step Guide

In my browser game, I am experiencing an issue with sound playback specifically in Google Chrome. Although the sound manager functions properly in other browsers, it returns a DOMException error after playing sounds in 50% of cases. I'm unsure what co ...

What is the equivalent of Typescript's Uint8Array and Uint16Array in Python?

new Uint8Array(new Uint16Array([64]).buffer) How can I achieve a similar data structure in pure Python? What is the equivalent of Uint8Array/Uint16Array? I am extracting a buffer from a Uint16Array type here and converting it to a Uint8Array, but I am un ...

Learn how to iterate over a JSON object using TypeScript in Angular5 to generate an array of objects

Here is a sample JSON code that includes an array "Customers" with objects and arrays nested inside: This is my JSON code snippet: { "Customers": [ { "customerData": { "secondLastName": "Apale", "firstLastName": "Lara", ...

String defines the type

I came across the following code snippet in some external sources that I intend to incorporate into my project: const INIT: 'jsonforms/INIT' = 'jsonforms/INIT' Can someone explain what it means to define a type with a string like INIT ...

How can you rearrange the order of objects in an array to only include duplicates?

https://i.sstatic.net/XwCDZ.png I don't want to alter the original order of objects in an array. However, I do need to retrieve items in a specific sequence when both the location and place are identical. I attempted a solution but it requires an ad ...

Creating an interactive element in Angular: A step-by-step guide

Hey there, I'm facing a problem with creating a specific payload structure as shown in the example code snippet below. Everything was going well until I got stuck at the dynamic form part, and despite several attempts, I can't seem to figure it o ...

Steps for obtaining the current state array post re-ordering column in Angular datatables

I am facing an interesting scenario where I can successfully retrieve the current state of an array of columns using pure JS + jQuery, but unfortunately, the same approach does not seem to work in Angular 12! Despite going through the documentation for Ang ...

Employing Bazel in conjunction with Lerna and Yarn workspaces

It seems that a lot of people are currently utilizing lerna and/or yarn workspace. I'm thinking about either transitioning from them to Bazel, or perhaps integrating them with Bazel in conjunction with an example project for guidance. Take for insta ...

Encountering challenges with the search and filtering features

I'm having some trouble with the search and filter features I'm creating. They work fine initially, but once I enter a search query in the input field, the results show up as expected. However, if I delete the query or enter a different one, the ...

Using Typescript to define classes without a constructor function

As I was going through the "Tour of Heroes" guide on the Angular website, I came across the following code snippet: class Hero { id: number, name: string, } const aHero: Hero = { id: 1, name: 'Superman' } console.log(aHero instanceof H ...

A guide on successfully sending parameters to Angular routes

Currently, I am delving into Angular and exploring various basic concepts such as routing, Observables (and subscribing to them), making HTTP requests, and utilizing routing parameters. One scenario I have set up involves sending a HTTP GET request to JSON ...

Unable to upload any further verification documents to Stripe Connect bank account in order to activate payouts

Query - Which specific parameters should I use to generate the correct token for updating my Stripe bank account in order to activate payouts? I've attempted to activate payouts for my Stripe bank account by using a test routing and account number (t ...

What could be causing Typescript Intellisense to not display Object extensions?

Let's take a look at this unique way to extend the Object type: interface Object { doSomething() : void; } Object.prototype.doSomething = function () { //perform some action here } With this modification, both of the following lines will c ...

Show a select element with choices that change depending on another select element

I am currently working on a select dropdown component that utilizes the @Input option variable. My goal is to have another instance of this component display options based on the selection made in the first instance. Any suggestions on how to make this h ...

Every field displaying a description above the input

Is there a way to customize the default wrapper for all fields? I am looking to have the description displayed above the fields instead of below them, which is the default behavior for Bootstrap. Check out this StackBlitz example: https://stackblitz.com/ ...

A mistake occurred during the afterAll function, resulting in a TypeError: Unable to access properties of an undefined entity (specifically, trying to read '

While creating my spec file and settings, I encountered an error in the console: 'An error was thrown in afterAll TypeError: Cannot read properties of undefined (reading 'toLowerCase')', What could be causing this error to appear? H ...

Error: Azure AD B2C user login redirect URI is not valid

Currently working on setting up user login with Azure AD B2C. I have successfully created an App Registration in my B2C tenant and specified http://localhost:3000 as the redirect URI. However, when implementing it in my React app using the MSAL React libra ...

Activate TypeScript EMCAScript 6 support for Cordova projects in Visual Studio

I am interested in utilizing the async/await feature of TypeScript in my VS2015 Cordova project. I have updated "target": "es6" in tsconfig.json Although there are no errors shown in intellisense, I encounter the following error while building the project ...

Adjust the observable value when making an API call

I have an observable that emits values from an API. In the component where it's subscribed, I want to update the observable value on a certain event. I'm struggling to figure out how to do this. Here is the code in the service class: cacheSett ...