All cards expanding simultaneously rather than singularly when defining with JSON data - html

Is it possible to expand my cards individually rather than as they are doing now, all together?
I have defined an array of JSON data that will be used to fill the details of the cards, but I just cannot seem to get them to expand individually.
Simple data
export const DATA = [
{
name: 'Some name 1',
},
{
name: 'Some name 2',
}
];
.ts file
export class AppComponent {
data;
expanded = [];
constructor(public toast: MatSnackBar) {
this.data = DATA;
}
}
html
<div class="container">
<mat-card *ngFor="let item of data" #panel [ngClass]="{expanded: expanded[item]}" [class.mat-elevation-z8]="expanded[item]">
<div class="header">
Some content here
<div class="toggle">
<button mat-icon-button>
<mat-icon *ngIf="!expanded[item]" (click)="expanded[panel]=!expanded[item]">
edit
</mat-icon>
<mat-icon *ngIf="expanded[item]" (click)="expanded[item]=!expanded[item]">cancel</mat-icon>
</button>
</div>
</div>
<div class="body" *ngIf="expanded[item]">
Some content here
</div>
</mat-card>
</div>
Here is my stackblitz for you to play with
Edit:
My 'logic' above comes from seeing something similarly implemented like this:
<mat-card #panel *ngFor="let x of [1,2,3]" [ngClass]="{expanded: thisExpands[x]}">
<div class="header">
<div class="toggle">
<button
mat-flat-button
(click)="thisExpands[x]=!thisExpands[x]"
...
However these cards are generated from a much more simple array of data.

you can use index to access the particular item in the forLoop:
<mat-card *ngFor="let item of data; let i = index">
</mat-card>
Your HTML Code:
<div class="container">
<mat-card *ngFor="let item of data; let i = index" #panel [ngClass]="{expanded: expanded[i]}" [class.mat-elevation-z8]="expanded[i]">
<div class="header">
Some content here
<div class="toggle">
<button mat-icon-button>
<mat-icon *ngIf="!expanded[i]" (click)="expanded[i]=!expanded[i]">
edit
</mat-icon>
<mat-icon *ngIf="expanded[i]" (click)="expanded[i]=!expanded[i]">cancel</mat-icon>
</button>
</div>
</div>
<div class="body" *ngIf="expanded[item]">
Some content here
</div>
</mat-card>
</div>
StackBlitz Example

<div class="container">
<mat-card *ngFor="let item of data; let i = index" #panel [ngClass]="{expanded: expanded[i]}" [class.mat-elevation-z8]="expanded[i]">
<div class="header">
Some content here
<div class="toggle">
<button mat-icon-button>
<mat-icon *ngIf="!expanded[i]" (click)="expanded[i]=!expanded[i]">
edit
</mat-icon>
<mat-icon *ngIf="expanded[i]" (click)="expanded[i]=!expanded[i]">cancel</mat-icon>
</button>
</div>
</div>
<div class="body" *ngIf="expanded[i]">
Some content here
</div>
</mat-card>
</div>
Try this one. Use index instead of item.

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 buttons won't work when inside mat-radio-group

I have a quiz application that displays multiple questions along with their respective answers. I am wanting to make it so each question has its own unique set of radio checkboxes so that I can easily bind that to a "Selected" property of an answer. When I try to do this it will let me select one radio button but then the other ones glitch out.
Video of problem. This seems to only happen when I put them inside of a mat-radio-group but I thought I had to use one to get different sets of radio buttons.
<!--start of exam -->
<mat-step [stepControl]="examForm">
<ng-template matStepLabel>
<span *ngIf="worksheetComplete"><span *ngIf="programLocked">Edit </span>Exam</span>
<span *ngIf="!worksheetComplete" class="text-red-400"><span *ngIf="programLocked">Edit </span>Exam (Incomplete)</span>
</ng-template>
<div *ngIf="examAttemptMap.passing" fxLayout="column" fxLayoutGap="24px">
<span *ngIf="sharedService.tablet" class="f-s-18">Exam</span>
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="24px">
<span fxFlex="70" class="f-s-20">You have already passed the exam. Please continue through the application.</span>
</div>
</div>
<div *ngIf="!examAttemptMap.passing" fxLayout="column" fxLayoutGap="24px">
<span *ngIf="sharedService.tablet" class="f-s-18">Exam</span>
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="24px">
<span fxFlex="70" class="f-s-20">Please answer the following questions. You may attempt this as many times as you would like.
</span>
</div>
<mat-radio-group formControlName="{{question.text}}" *ngFor="let question of examAttemptMap.questions; let elementIndex = index">
<!--Questions-->
<div fxLayout="column" fxFlex="100" >
<!--Core Elements-->
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="8px" fxLayoutAlign="start center" fxLayoutAlign.lt-md="" style="padding-bottom: 1%" >
<span><strong>({{elementIndex + 1}})</strong></span>
<span>{{question.text}}</span>
</div>
<!--Answers-->
<div fxLayout="row">
<span fxFlex="5"></span>
<div fxLayout="column" fxFlex="80">
<div fxLayout="column" *ngFor="let answer of question.examAnswers; let subSectionIndex = index" fxLayoutGap="8px">
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="8px" fxLayoutAlign="start center" fxLayoutAlign.lt-md="">
<mat-radio-button value="true"></mat-radio-button>
<mat-card [ngStyle]="{'background-color':(answer.selected == true) ? '#53a66c' : '#00559525' }" (click)="highlightCard(answer, question.examAnswers)" [id]="answer.selected" class="card" >
<span ><strong>({{getIndexLetter(subSectionIndex, false)}})</strong></span>
<span style="padding-left: 1%">{{answer.text}}</span>
</mat-card>
</div>
</div>
</div>
</div>
</div>
</mat-radio-group>
</div>

In ngx-scrollreveal , ngsReveal is Hiding components which should animate on scroll

<mat-drawer-container style="text-align: center;" class="example-container">
<mat-drawer mode="side" #drawer opened>
<div fxFill class="side-card">
<mat-card-title ngsReveal>
<mat-icon>landscape</mat-icon> Property Cloud
<mat-icon>landscape</mat-icon>
</mat-card-title>
<mat-card class="side-menu">
<mat-card-header>
<div class="example-header-image"></div>
<mat-card-subtitle></mat-card-subtitle>
</mat-card-header>
<hr>
<mat-card-content>
</mat-card-content>
<div style="text-align: center;" class="mt-5">
<div class="t-5">
<button ngsReveal mat-raised-button><a routerLinkActive="active" routerLink="property_feed"> </a>Property feed</button>
</div>
<div ngsReveal class="t-5">
<button mat-raised-button>My Account</button>
</div>
<div class="t-5">
<button ngsReveal mat-raised-button>My Properties</button>
</div>
<div class="t-5">
<button ngsReveal mat-raised-button> My Wishlist</button>
</div>
<div class="t-5">
<button ngsReveal mat-raised-button> Settings and privacy</button>
</div>
</div>
</mat-card>
</div>
</mat-drawer>
<mat-drawer-content>
<div fxFill class="main-card">
<app-header (toggleEmitter)="drawer.toggle()"></app-header>
<div fxLayout="row wrap" >
<div *ngFor="let ppty of property">
<div ngsReveal fxFlex>
<mat-card class="property-feed">
<mat-card-header>
<div mat-card-avatar class="avatarImage"></div>
<mat-card-title >Card Title</mat-card-title>
<mat-card-subtitle >Card Subtitle</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<app-gallery ></app-gallery>
<h3>some informaion to the end user</h3>
</mat-card-content>
<mat-card-footer>
</mat-card-footer>
<mat-card-actions>
<button matTooltip="If intrested contact seller" mat-fab large color="primary">
<mat-icon>thumb_up_alt</mat-icon>
</button>
<button matTooltip="If intrested add to wishlist" mat-fab large color="warn">
<mat-icon>add_shopping_cart</mat-icon>
</button>
<button matTooltip="View details" mat-fab large color="warn">
<mat-icon>unfold_more</mat-icon>
</button>
</mat-card-actions>
</mat-card>
</div>
</div>
</div>
</div>
</mat-drawer-content>
</mat-drawer-container>
In ngx-scrollreveal , ngsReveal is Hiding components which should animate on scroll.Only components which is within viewport of website is showing and animating. other than cards which should reveal on scroll is hidden.I could see the cards are present there, since i have a click event, its working but components are hidden. And I couldn't see any console errors.
"./node_modules/scrollreveal/dist/scrollreveal.min.js", is imported in angular.json
Its working for element except in viewport,On later experiemnting by placing content in different places.
div is getting hide because its placed under mat-drawer-content. Any idea why its hiding elements that is not coming at the first time loading.
I could see the difference for this displayed card's html and hidden card's html is different in case of opasity but dont know what is causing it. Its working fine except inside mat-drawer-container.
import { Component, OnInit } from '#angular/core';
import { NgsRevealConfig } from 'ngx-scrollreveal';
#Component({
selector: 'app-property-feed',
templateUrl: './property-feed.component.html',
styleUrls: ['./property-feed.component.scss'],
providers: [NgsRevealConfig]
})
export class PropertyFeedComponent {
property =[1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10];
}
button {
margin: 5px 5px 5px 5px;
}
.feed-title {
font-size: 30px;
font-family: "Girassol", cursive;
}
.property-feed {
width: 300px;
height: 410px;
margin-top: 15px;
margin-right: 10px;
}
#media only screen and (max-width: 600px) {
.property-feed {
width: 300px;
height: 410px;
margin-top: 10px;
margin-right: 5px;
}
}
<!-- begin snippet: js hide: false console: true babel: false -->
[ngsReveal]="{delay: some_delay, reset: false}"
Try using binding it's properties with html element!
PS: I am not sure that this will work in your scenario or not.
Try add className (button) and add your class name to container
<button class="button" [ngsReveal]="{reset: true, container: '.button'}" mat-raised-button> My Wishlist</button>

display flex does not break long lines as expected

Trying to display a list of things in a single line using flex display. I am using angular 7 for development.
Below is the HTML I implemented:
<div class="d-flex">
<span>Other: </span>
<div class="d-flex">
<div *ngFor="let allergy of allergies; let i = index">
<span *ngIf="i > 0">,</span><span *ngIf="allergy"> {{ allergy }}</span>
<span *ngIf="!allergy">None</span>
</div>
</div>
</div>
d-flex is the bootstrap display class:
.d-flex {
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
}
In my component allergies is set to
allergies = ['dermatological allergies', 'dust', 'pollen', 'mold'];
Display:
As seen, the list does not break properly and the display is distorted. This happens when the list length exceeds the computed column width. How can I display it as a list that breaks properly as expected? Please let me know if I can improve my question or if I can provide any more information.
I think this is what you want:
<div class="d-flex">
<span>Other: </span>
<div>
<ng-container *ngFor="let allergy of allergies; let i = index">
<span *ngIf="allergy">{{ allergy }}</span><span *ngIf="i < allergies.length - 1">, </span>
<span *ngIf="!allergy">None</span>
</ng-container>
</div>
</div>
Here is a stackblitz example showing how this looks like.
Hope this helps...
With angular, I suggest you to use Flex-layout from Angular.
With your to wrap your item, use row wrap
With your code, you can also do:
<div class="d-flex">
...
...
<div *ngFor="let allergy of allergies; let i = index" class="d-flex">
...
</div>
</div>
</div>

Hide div when add items - ionic framework

Im trying to hide specific div (empty state) when i add some item from add button, any ideas how can i do that easily?
Best Regards, Will.
page.html
<ion-content>
<!-- DIV ABOVE -->
<div class="center-div">
<img src="assets/imgs/noItem.svg" />
<div class="center">
<h1>Empty List</h1>
</div>
</div>
<ion-refresher (ionRefresh)="doRefresh($event)">
<ion-refresher-content pullingIcon="arrow-dropdown" pullingText="Pull to refresh" refreshingSpinner="circles" refreshingText="Refreshing...">
</ion-refresher-content>
</ion-refresher>
<ion-list>
<button *ngFor="let item of items" ion-item (click)="goToItemDetail(crop)">
...
</ion-list>
<ion-fab right bottom>
<button ion-fab class="button-fab" (click)="addItem()">
<ion-icon name="add"></ion-icon>
</button>
</ion-fab>
</ion-content>
Yes, you can hide div with the help of *ngIf="condition"
<div class="center" *ngIf="items">
<h1>Empty List</h1>
</div>
or you can also check boolean varible on button like
// isVisible: boolean
addItem() {
this.isVisible = false;
}
<div class="center" *ngIf="!isVisible">
<h1>Empty List</h1>
</div>