How to show specific information for individual items using Angular

In my current project, I am utilizing angular 7 and bootstrap 4. My goal is to display detailed information right below the selected item. The screenshot below shows where I'm currently at: https://i.sstatic.net/su9tI.jpg

Here is what I aim to achieve:

https://i.sstatic.net/aDw0C.jpg

Currently, the team details appear at the bottom of the page, as shown in the first picture. However, I want the team detail to be positioned exactly below the selected card.

Below is a snippet of my code:

TeamListComponent

export class TeamListComponent implements OnInit {

  teams: any;

  constructor(private ts: TeamsService) { }

  ngOnInit() {
    this.ts.getTeams().subscribe(data=> {
      this.teams = data.teams;
    })
  }
}

TeamListTemplate; Note: The router-outlet directs to the team detail component.

<div class="container-fluid">
  <div class="row">
    <app-team *ngFor="let team of teams" [team]=team></app-team>
  </div>
<div class="row">
  <router-outlet></router-outlet>
</div>
</div>

Single team component

export class TeamComponent{
      @Input() team: any;
}

Team template: Note: Bootstrap cards are used to showcase the team.

<div class="card border-dark " style="width: 300px; height: 450px; margin: 10px;" [routerLink]="team.id"
     routerLinkActive="active">
  <img class="card-img-top embed-responsive" src="{{team.crestUrl}}" alt="Card image cap">
  <div class="card-body">
    <h5 class="card-title">{{team.name}}</h5>
    <p class="card-text">{{team.address}}</p>
    <a href="{{team.website}}" class="btn btn-outline-dark btn-lg btn-block" target="_blank">Visit Website</a>
  </div>
</div>

If you have any suggestions or need more specific details, please don't hesitate to reach out. Thanks in advance!

Answer №1

<div class="container-fluid">
  <div class="row">
    <app-team *ngFor="let team of teams" [team]=team></app-team>
    <div>Place your router-outlet within the same row and make any necessary adjustments for your needs.</div>
  </div>
</div>


Ensure that your router-outlet is properly positioned within the row element to meet your requirements.

Answer №2

To address this issue, consider nesting your

<team-detail></team-detail>
within the <team></team> element. By clicking on it, the
<team-detail></team-detail>
will be displayed below that particular component.

Alternatively, you can utilize

<ng-content></ng-content>
inside the <team></team> and include
<team-detail></team-detail>
like so:

<team>
  <team-detail></team-detail>
</team>

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

Having trouble with overriding an @media query for material-ui react components?

I've been trying to modify a @media CSS rule on a Material UI component, similar to the discussions on How to over-ride an @media css for a material-ui react component and Override components like MuiTab that use media queries. However, I have not bee ...

How about trying out some dropdowns?

Following the issue I mentioned in my previous question titled Margin-Right on CSS not working, I am currently engaged in a creative endeavor to redesign my school's website homepage. The progress so far has been significant, but I now require some as ...

What is the best way to disconnect an ngFor loop from its original context and reconnect it to a wrapping component's context when utilized as projected content?

In my project, I've developed a custom wrapping component that accepts <div *ngFor='let item of items> as part of its projected content. My goal is to replace the immediate bindings within the projected content with those defined in the wr ...

Unique style for custom vue multiselect component

I have implemented a Vue Multiselect component, but I am struggling to fully customize it with CSS styles. I have applied some CSS styles, but I am unable to achieve all the customization I want. Specifically, I want to modify the option height, select box ...

Stop the automatic hiding of the sticky header when reaching the bottom of the page

I have implemented the position: sticky property for my website's header. However, I am facing an issue where the header becomes hidden when I scroll halfway down the page (bottom on mobile devices). Can anyone suggest a solution to fix this problem? ...

"Error in Visual Studio: Identical global identifier found in Typescript code

I'm in the process of setting up a visual studio solution using angular 2. Initially, I'm creating the basic program outlined in this tutorial: https://angular.io/docs/ts/latest/guide/setup.html These are the three TS files that have been genera ...

An alternative to Firebug for Internet Explorer

Can anyone suggest a suitable replacement for Firebug that is compatible with IE 7 and 8? I need a tool that allows me to edit CSS/HTML in real-time, debug JavaScript code, and visualize the positions of elements on web pages. Appreciate any recommendati ...

"Implement a feature in JavaScript that allows users to click on images to navigate

I have a navigation feature on my website that allows me to cycle through images using the following code: <a href="JavaScript:previousImage()">Previous</a> | <a href="JavaScript:nextImage()">Next</a> <span id='num' ...

Is there a way to determine the negative horizontal shift of text within an HTML input element when it exceeds the horizontal boundaries?

On my website, I have a standard HTML input field for text input. To track the horizontal position of a specific word continuously, I have implemented a method using an invisible <span> element to display the content of the input field and then utili ...

Refresh Angular Component upon query parameter modification

Within my application, there is a search form that can be accessed by adding query parameters to the URL. This will prefill the form with specific information. My goal is to clear this prefilled state when the search icon in the navigation is clicked. Whi ...

Can absolute positioning of an element impact the relative positioning of the element below it? What steps can be taken to

The webpage contains rows that are relatively positioned. Each row consists of col1 and col2, which are floated to the left and right, respectively. However, there seems to be an issue with the last row where col1 and col2 are not floating as expected. I ...

Is the item positioned above another item instead of being positioned to the left of it?

Looking for help with my mobile navigation setup. I want to add text that says ' ...

Continuous animation for a sequence of overlapping images with smooth transitions

Currently, I am in the process of developing a JavaScript script that will cycle through a series of images within the same <div>. The goal is to create a seamless animation effect with the image transitions. Although the images are cycling through, ...

Tips for structuring a news thread with a staggered approach

On my Drupal 8 website, I have set up a newsfeed. How can I display the news items in staggered rows? I would like the first item to align on the left and the second item to be on the right, repeating this pattern for all subsequent items. Currently, I am ...

Turning a bootstrap form input into a clickable element by adding a font-awesome icon

I am facing an issue with my date input field and a font awesome icon placed on top of it. The appearance is correct, but I am unable to click on the input when the mouse is hovering over the icon. Despite trying to adjust the z-index, the problem persists ...

What is the best way to overlay an image on two divs/containers simultaneously?

I've been tasked with creating a web mockup featuring a transparent PNG image overlaying two divs in multiple rotations. I've used Bootstrap 4.1 to structure the site, utilizing containers, rows, and cols. <section class="one"> <!-- ...

Guide to hosting a Razor partial view within Angular, without using IIS

Exploring an age-old topic on How to utilize ASP.Net MVC View .csthml as Angular View rather than .html I am seeking a similar solution but with Angular 15 and VS Code. My goal is to develop Angular components within VS Code for an ASP.NET MVC site (not W ...

Why doesn't the background color display properly when the div height is set to auto?

When I set the height of #container to auto, the background-color does not display. However, when I set it to a fixed height like 1000px, it shows up. I've attempted using "overflow:auto", but that did not solve the issue. How can I fix this? I want # ...

What causes the test div's height to increase when using position:absolute?

The div.test was initially set with a height of auto, meaning no fixed height. .test { top: 0px; right: 0px; bottom: 0px; left: 0px; background: yellow; width: 200px; height: auto; padding: 10px; } <div class="test"> This is some ...

Tips for including space at the beginning and end of a dynamically created table cell

My table is dynamically generated with contents drawn from a database, creating rows based on the data. Each cell has a rounded border and 2px padding for consistency. I want all cells to appear evenly spaced and padded vertically, but I'm facing an ...