Having trouble getting past the initial iteration in Angular's modal system?

Having trouble generating a modal for every iteration in ngFor. The data passed to the modal seems to be stuck in the first iteration and doesn't change with each iteration. Any ideas on how to solve this?

<div class="container">
    <div *ngFor="let note of allNotes.slice().reverse()">
        <div class="card">
            <div style="padding: 20px;">
                <img class="card-img-top" src="../../assets/angular.png">
            </div>

            <div class="card-body">
                <h5 class="card-title">{{note.title}}</h5>
                <p class="card-text">{{note.content | summary:300 }}</p>
                <button type="button" class="btn btn-info btn-lg" (click)="openModal(note)">Show Details</button>
                <!-- Modal Starts -->
                <div class="modal" role="dialog" [ngStyle]="{'display':display}">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title">{{ note.title }}</h4>
                                <button type="button" class="close" aria-label="Close" (click)="onCloseHandled()"><span
                                        aria-hidden="true">×</span></button>
                            </div>
                            <div class="modal-body">
                                {{ note.content }}
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" (click)="onCloseHandled()">Close</button>
                                <button type="button" class="btn btn-primary">Delete Note</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Modal Ends -->
            </div>
            <div class="card-footer">
                {{ note.time | timeAgo }}
            </div>
        </div>
    </div>
</div>

Here is my .ts file for reference:

import { Component, OnInit } from '@angular/core';
import notes from '../notes.data';

@Component({
  selector: 'show-notes',
  templateUrl: './show-notes.component.html',
  styleUrls: ['./show-notes.component.css']
})
export class ShowNotesComponent implements OnInit {
  allNotes = notes;
  constructor() { }

  ngOnInit(): void {
  }

  display = "none";

  openModal() {
    this.display = "block";
  }
  onCloseHandled() {
    this.display = "none";
  }
}

If you have any suggestions or solutions, I would greatly appreciate your help! Thank you.

Answer №1

If you choose to use the slice() method, make sure to provide both start and end values. However, if your goal is simply to reverse the elements, consider removing the slice() call altogether.

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

several different objects within the rightIconButton of a ListItem component in MaterialUI

I am currently working on a project where I need to add multiple elements to the rightIconButton of a ListItem. The tools I am using are Material UI v0.20 and [email protected] <ListItem rightIconButton={ <span> ...

Can Ember store in Route handle Post requests?

Is there a way to use ember store functionality similar to this.store.findAll('report') for making POST requests with postObj in my route? Also, how should I handle the response received from these requests? Right now, I am sending ajax POST requ ...

Combining PHP and Javascript for a single form submission to two different forms

Have you come across these discussions? submit a form inside another form Submitting form data to two locations using Javascript and PHP? Unfortunately, neither of them provides a satisfactory answer to the question. Allow me to paint the picture for ...

Using jQuery to dynamically add a value to a comment string

Is there a way to dynamically include tomorrow's start and end times in the message for the setupOrderingNotAvailable function if today's end time has passed? The current message states that online ordering will be available again tomorrow from 1 ...

Retrieve active route information from another component

We are utilizing a component (ka-cockpit-panel) that is not linked to any route and manually inserted into another component like so: .. ... <section class="ka-cockpit-panel cockpit-1 pull-left"> <ka-cockpit-panel></ka- ...

How to extract the text content of an element using XPath in Selenium?

I have a setup that looks like this : <div class="content"> <h3 class="faq">Joocey</h3> Locked Bag 4005 <br> 6/78 William Street <br> Sydney NSW 2000 <br> Customer Ca ...

The state of the button remains unchanged in jQuery/Rails 3

After immersing myself in the Hartl Rails 3 tutorial for a few days (about 4 to be exact), I encountered an issue while attempting to convert the site from prototype to jQuery in chapter 12. The problem lies in getting the "follow"/"unfollow" button to upd ...

How can I sync changes between two variables in node.js?

Is there a method to create a shared variable in JavaScript? Here is an example of what I am attempting to achieve: var id = 5; var player = new Player(id); var array1[0] = player; var array2[0] = player; array1[0].id = 8 console.log(array1[0]); // ...

`Anomaly detected in image grid display`

The images are not resizing according to the container. Despite setting both height and width to 100%, the image is not taking the width of the outer column container. https://i.sstatic.net/10eMg.jpg This is what I expected This is the result I am current ...

TypeError: describe is not a function in the Mocha testing framework

Encountering an issue with mocha-typescript throwing an error indicating that describe is not defined. TypeError: mocha_typescript_1.describe is not a function at DatabaseTest.WrongPath (test/database_test.ts:21:9) at Context.<anonymous> ...

Create a JavaScript function that performs multiplication and returns two distinct calculations

Upon examination of the embedded script below, I noticed that it is only providing a single result (500). How can I modify my code to generate both results? Your advice on this matter is greatly appreciated. function multiplier() { var number = 2 ...

Childs - A jQuery Stride

I am trying to figure out how to modify a specific child element within an HTML structure. Specifically, I want to target the first anchor tag within a list item of an unordered list. Here is what I have attempted so far: [HTML AND JQUERY] <body> ...

Implementing Jquery tabs into the code causes the vertical auto-scroll to smoothly glide beyond anchor points

I recently implemented a smooth autoscroll feature on my webpage using the CSS-Tricks code found here: http://css-tricks.com/snippets/jquery/smooth-scrolling/ Everything was working perfectly until I added jQuery tabs to display some of the content. Now, ...

What is the best starting dataset to use from a large pool of data points when creating a stock line chart in High

I am working on creating a line stock highchart similar to the example shown here: https://www.highcharts.com/demo/stock/lazy-loading In the provided example, the initial load fetches data from https://demo-live-data.highcharts.com/aapl-historical.json, s ...

Guide to adding a play button overlay to an image with the use of javaScript

I've been exploring ways to incorporate an overlay play button onto an image, allowing me to click on it and play a video. My main concern is that most solutions require adding a distinct overlay play button directly to the source code. However, what ...

Utilize Angular 4 to effectively update objects within Firebase Cloud Firestore

Hey there! I've been working with firebase and angular 4 on this new thing called firestore. I've been trying to update one of the documents, but I keep encountering this error. https://i.sstatic.net/638E1.png Here's my component: https:/ ...

Problem with Pinia: nested array in an object

My unique store located within a vue3 application, contains an object called currentReservation with a property named pricings which is an array. Each pricing includes an id and quantity. When I add a new pricing, it is added to both the store and compone ...

Body of the Bootstrap modal

Currently using bootstrap modal-body and bootstrap-switch-container, but the issue is that the class = "bootstrap-switch-container" doesn't function properly within the class="modal-body". It just displays as a checkbox. Here is the cshtml code I wa ...

Aligning bootstrap side by side fields poses a challenge when labels are missing

I am struggling to design a basic bootstrap layout as I am facing challenges in aligning controls that lack labels. The problem can be seen in the provided fiddle. The controls (textbox and button) in the third column are not aligned next to the Last name ...

What steps can be taken to address the problem of the "incorrect referer value" when sending a form?

I am experiencing some challenges with accessing a certain forum as my IP address has been blocked. It seems that another user may have violated the rules and their ISP or IP address is similar to mine, causing me to be impacted. I attempted to post comm ...