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>
Related
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.
if I put my mouse pointer on one of the info buttons, it will show both tooltips. How can I prevent this? I just want to show the one tooltip, on which the mouse pointer points to. Does anyone have an idea?
Here is the code:
<div class="col-12 col-lg-6">
<div class="dx-fieldset-header">Dateianhänge<span class="dx-fieldset-header-subtext"> Download / Löschen</span></div>
<div class="dx-field">
<div class="anhang-liste">
<mat-chip-list *ngIf="data?.anhanglist.length" aria-label="Anhänge löschen">
<mat-chip *ngFor="let anhang of data?.anhanglist" class="anhang-chip">
<span class="anhang-filename" (click)="downloadAnhang(anhang)">
{{ anhang.dateiname }}
</span>
<mat-icon *ngIf="!IstAnhangBereitsInKontoauszugszeileVerwendet(anhang.id)" class="anhang-delete" (click)="deleteAnhang(anhang)">cancel</mat-icon>
<i
*ngIf="IstAnhangBereitsInKontoauszugszeileVerwendet(anhang.id)"
style="margin-left: 0.2em;"
class="fa fa-info-circle"
id="infoKontoauszugzeilenAnhang{{anhang.id}}"
(mouseenter)="toggleDefault()"
(mouseleave)="toggleDefault()"
>
<dx-tooltip
*ngIf="IstAnhangBereitsInKontoauszugszeileVerwendet(anhang.id)"
target="#infoKontoauszugzeilenAnhang{{anhang.id}}"
[(visible)]="defaultVisible"
[closeOnOutsideClick]="false"
>Verwendet in folgenden Kontoauszugzeilen:
{{zeilenNummernMitAnhang[anhang.id]}}
</dx-tooltip>
</i>
</mat-chip>
</mat-chip-list>
</div>
</div>
</div>
I have a problem with Anguar8 and ngIf:
I have a code that creates div which loads some images and their details to a page from a json with conditon:
HTML Code:
<div class="row" >
<div class="col-md-2 col-6 col-sm-4" style="margin-bottom: 1em;" *ngFor="let item of product; let i=index"> <br>
<div class="box" *ngIf="i>35">
<img [src]="item.photo" alt="image slide" style="display: block; width: 100%;">
<div class="text-center">
<h6>{{item.name}}</h6>
<h6>MRP : ₹ {{item.price}}</h6>
</div>
</div>
</div>
</div>
The problem is, that angular creates an empty div with this comment in it:
<div _ngcontent-oio-c3="" class="col-md-2 col-6 col-sm-4" style="margin-bottom: 1em;"><br _ngcontent-oio-c3=""><!--bindings={
"ng-reflect-ng-if": "false"
}--></div>
You may write *ngFor="let item of product | slice:0:35;".
Reference https://angular.io/api/common/SlicePipe
There are two options:
1.You can filter the list using pipe to avoid
2.You can try this should not create any template
<div *ngIf="i>35; else noData">
{{data}}
</div>
<ng-template #noData>
</ng-template>
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.
I am trying to add a feature just like stack overflow comments where clicking on the edit link the div transforms to a text box and we get a submit button .
But the problem is i have multiple comments which i am populating via ngFor how do i remove the property readonly from the selected div in which the edit has been clicked .
This is what i have tried.
<div class="tab-content">
<div id="email" class="tab-pane active">
<div *ngFor="let i of comments; let index = index" [#flyInOut]>
<div class="well">
<input type=”text” value="{{i.comment}}" [readonly]="false" /><span>
Edited <time>{{today | amDifference: i.createdAt :'minutes'
: false}}</time> before
</span><a><i
class="align remove glyphicon glyphicon-remove-sign glyphicon-white"
(click)="edit(index)"></i></a>
</div>
</div>
</div>
</div>
I also i would love to have something like checking time i have already done the backend part of same how to only enable the edit button for the comment where the amDifference is less than 5 mins and then we show a delete option.
You can use ngIf-Else to provide a second template to show like such:
<div class="tab-content">
<div id="email" class="tab-pane active">
<div *ngFor="let i of comments; let index = index" [#flyInOut]>
<div *ngIf="i.editMode; else editBlock" class="well">
<!-- Show stuff here -->
<a>
<i class="align remove glyphicon glyphicon-remove-sign glyphicon-white"
(click)="i.editMode=true">
</i>
</a>
</div>
<ng-template #editblock>
<div class="well">
<!-- Edit stuff here -->
<input type="button" (click)="i.editMode=false" value="Done"/>
</div>
</ng-template>
</div>
</div>
</div>