Wrap material cards inside an ngFor - html

I'm generating cards from an Api when user makes a search.
I have film list component in which I show my cards
here's the HTML
<div fxLayout='row' fxLayoutWrap class="cards">
<div fxFlex="20" class="example-card" *ngFor="let film of dataResult.results">
<mat-card>
<mat-card-header>
<mat-card-title>{{film.title}}</mat-card-title>
<mat-card-subtitle>{{film.release_date}}
</mat-card-subtitle>
</mat-card-header>
<img mat-card-image src="http://image.tmdb.org/t/p/w185/{{film.poster_path}}" alt="Photo of a Shiba Inu">
<mat-card-content>
<p>
{{film.overview}}
</p>
</mat-card-content>
<mat-card-actions>
<button mat-button>
<mat-icon>favorite</mat-icon>
</button>
<button mat-button>SHARE</button>
</mat-card-actions>
</mat-card>
</div>
</div>
And CSS
.example-card {
min-width: 100%;
margin: 40px;
}
.cards {
width: 400px;
}
the services are working and also component ts logic.
My problem is that material cards are not wrapping to a new line while I'm using fxLayoutWrap to wrap content when fxFlex get 100 of value.
Here's a stacklitz demo ( I get an https error when I call the API, if someone could fix it I'll be grateful )
Here's a screenshot of my problem

<div fxLayout='row' fxLayoutWrap class="cards">
<div fxFlex="20" class="example-card">
<mat-card *ngFor="let film of dataResult.results" style="margin-top:10px;>
<mat-card-header>
<mat-card-title>{{film.title}}</mat-card-title>
<mat-card-subtitle>{{film.release_date}}
</mat-card-subtitle>
</mat-card-header>
<img mat-card-image src="http://image.tmdb.org/t/p/w185/{{film.poster_path}}" alt="Photo of a Shiba Inu">
<mat-card-content>
<p>
{{film.overview}}
</p>
</mat-card-content>
<mat-card-actions>
<button mat-button>
<mat-icon>favorite</mat-icon>
</button>
<button mat-button>SHARE</button>
</mat-card-actions>
</mat-card>
Because there is no problem repeating the code, you must be sure to place the repeat command as well as the essence of the code in the smart design material, and the codes are merged in the absence of space, so they must be separated for them Write css style margin-top:10px.
Verify the code above for you.

the fxLayout attribute can take a second parameter "wrap" which will do what you're looking for.
<div fxLayout="row wrap"></div>

Related

Using mat-grid-list within a mat-card to display multiple other mat-cards in a specific layout

Within an Angular project, I'm trying to replicate this.
I have a parent mat-card element which will house a mat-grid-list.
The mat-grid-list will then contain multiple (10) mat-cards which would in turn surround another mat-card (see the example image for the layout provided).
Is something like this possible and if so, what would the best approach be to do so?
Currently, with what I have, the child mat-cards (mat-card-2's in the example) are displaying in a single column.
HTML
The following is within a separate component which calls the "x" component
<mat-card-content *ngFor="let x of xs">
<div>
<app-x-synopsis [x]="x" ></app-x-synopsis>
</div>
</mat-card-content>
HTML for the "x" component
<mat-grid-list cols="6">
<mat-grid-tile id="table-grid" [colspan]="6" [rowspan]="1">
<mat-card class="x-synopsis-card">
<mat-card-header class="x-name">
<mat-card-title class="title">
{{ x.name }}
</mat-card-title>
<div style="flex-grow: 1"></div>
<button mat-icon-button>
<fa-icon [icon]="faInfoCircle"></fa-icon>
</button>
</mat-card-header>
<mat-card-content class="x-occupied" *ngIf="hasX()">
<div class="x-container" fxLayout="row wrap" fxLayoutAlign="space-around center">
<div class="ux-container" fxLayout="column">
<div class="ux-value">
{{ x.y.z }}
</div>
<div class="ux-title">
UX
</div>
</div>
<div class="abc">
{{ x.y.a }}
</div>
</div>
</mat-card-content>
<mat-card-content class="x-vacant" *ngIf="!x()">
<div class="x-container" fxLayout="row wrap" fxLayoutAlign="space-around center">
<div class="label">
VACANT
</div>
</div>
</mat-card-content>
</mat-card>
</mat-grid-tile>
</mat-grid-list>
Any help would be greatly appreciated, I am also happy to provide anymore information where possible :) Thanks.

Angular material card menu at the top right

How to add menu at the top right of the card using angular material, as per the https://material.angular.io/components/card/overview document there is no tag for that.
I want to add a button with icon at the right top as shown in the picture
<mat-card class="custome-card">
<a [routerLink]="['/products/123']">
<img mat-card-image
src="https://wonderfulengineering.com/wp-content/uploads/2013/12/Lamborghini-wallpaper-14.jpg"
alt="Photo of a Shiba Inu">
</a>
<mat-card-content>
<a [routerLink]="['/products/123']" class="productDetail"><span
class="mat-subheading-2">Lamborghini Aventador</span></a><br>
<span>NRs 1 - 2 Crore</span><br>
<strong>Size: </strong> <span>XL L M S XS</span>
</mat-card-content>
<mat-card-actions>
<div fxLayout="row" fxLayoutAlign="center">
<falcon-button [field]="favoriteBtnConfig"></falcon-button>
<falcon-button [field]="shareBtnConfig"></falcon-button>
<falcon-button [field]="shopCartBtnConfig"></falcon-button>
</div>
</mat-card-actions>
</mat-card>
The above code create the image as below
This solve the issue
.mdl-card__menu {
position: absolute;
right: 16px;
top: 16px;
}

display flex on mat-grid-tile Angular

I am trying to make the cards inside of the mat-grid-tile to be more spaced out using a display: flex;
However, the cards are stuck together and have no space between them. What should I do to make them look more spaced out?
HTML
<mat-grid-tile [colspan]="3" [rowspan]="2" class="productTile">
<mat-card *ngFor="let product of products" class="productCard">
<mat-card-header>
<ngx-avatar mat-card-avatar class="my-avatar" value={{product.authorInitials}} *ngIf="product.authorProfile == ''" class="avatar-header" size="40"> </ngx-avatar>
<ngx-avatar mat-card-avatar class="my-avatar" src={{product.authorProfile}} *ngIf="product.authorProfile != ''" class="avatar-header" size="40"> </ngx-avatar>
<mat-card-title>{{product.title}}</mat-card-title>
<mat-card-subtitle>{{product.author}}</mat-card-subtitle>
<button mat-icon-button matTooltip="Edit Post"><mat-icon class="toggle-icon">edit</mat-icon></button>
<button mat-icon-button matTooltip="Delete Post" (click)="deletePost(product.postID)"><mat-icon class="toggle-icon">delete</mat-icon></button>
</mat-card-header>
<img mat-card-image [src]="product.imageLinks ? product.imageLinks[0] : null" alt="Photo" class="cardImage">
<mat-card-content>
<p>
{{product.description}}
</p>
</mat-card-content>
<mat-card-actions>
<button mat-button>SHARE</button>
</mat-card-actions>
</mat-card>
</mat-grid-tile>
SCSS
.productTile{
display: flex;
justify-content: space-around;
}
Please look at this answer :
How to set row spacing in Angular Material's Grid?
You can use property gutterSize

How to make a list of Angular mat-card same size

I am rendering a list of asdfasd in Angular, but the images I upload are of different sizes, which causes some asdfasd to be bigger than others. How to make them the same size?
Here is the HTML
<div class="cardList">
<ng-container *ngFor="let card of comics">
<mat-card class="example-card">
<mat-card-content>
<mat-card-header>
<div mat-card-avatar class="example-header-image"></div>
<mat-card-title>{{card.name}}</mat-card-title>
</mat-card-header>
<img mat-card-image [src]="card.picture">
<mat-card-content>
<p>
{{card.description}}
</p>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" (click) = "openDialog(card)">${{card.amount}}</button>
</mat-card-actions>
</mat-card-content>
</mat-card>
</ng-container>
</div>
<mat-divider></mat-divider>
Try with this
mat-card img{
object-fit: cover; /*this makes the image in src fit to the size specified below*/
width: 100%; /* Here you can use wherever you want to specify the width and also the height of the <img>*/
height: 80%;
}
Reference

Correct mat-card-avatar image height in mat-ccard-header

As a personal project, I'm building a website using angular for one of my buddies. It may or may not ever go live, but I'm doing the project for my own personal learning. I've been a web app tester for the past five years, but only developed in a handful of situations, so I apologize if I'm incredibly naive or inexperienced.
I have a series of mat-card's that I'm putting information about centres around my province in (address, phone number, etc.) and I want to include each centre's logo/image as the mat-card-avatar. Right now, I have this:
My HTMLis here:
<mat-card class="centres-card" *ngFor="let centre of centres">
<mat-card-header fxLayout fxLayoutAlign="start center">
<div mat-card-avatar>
<img class="avatar" src="{{centre.img}}">
</div>
<mat-card-title>{{centre.name}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>
{{centre.streetAddress}}
<br>
{{centre.city}}, {{centre.province}}
<br>
{{centre.postalCode}}
</p>
</mat-card-content>
</mat-card>
</div>
My question is, I don't understand why both the header text and content text are overlapping the image, and not being pushed down by it.
Thanks so much for the help.
There are two options to get what you're looking for:
Option 1: use a div with mat-card-avatar and set the background
from you TS array
Option 2: use an img with mat-card-avatar ad set
the source
You were putting <img> inside the div with mat-card-avatar...
relevant HTML:
<h2>Option 1</h2>
<div *ngFor="let centre of centres">
<mat-card class="centres-card">
<mat-card-header fxLayout fxLayoutAlign="start center">
<div mat-card-avatar class="example-header-image"
[ngStyle]="{'background-image': 'url(' + centre.img + ')'}">
</div>
<mat-card-title>{{centre.name}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>
{{centre.streetAddress}}
<br>
{{centre.city}}, {{centre.province}}
<br>
{{centre.postalCode}}
</p>
</mat-card-content>
</mat-card>
</div>
<h2>Option 2</h2>
<div *ngFor="let centre of centres">
<mat-card class="centres-card">
<mat-card-header fxLayout fxLayoutAlign="start center">
<img mat-card-avatar src="{{centre.img}}">
<mat-card-title>{{centre.name}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>
{{centre.streetAddress}}
<br>
{{centre.city}}, {{centre.province}}
<br>
{{centre.postalCode}}
</p>
</mat-card-content>
</mat-card>
</div>
relevant CSS:
.example-header-image {
background-size: cover;
}
working stackblitz here