Reputation: 163
I'm pretty new to Angular but have been asigned a project which is written in Angular.
Looking at the .ts file which contains the list of property types I need to include a span around the label text. Is this possible?
Current list inside .ts file
export const extraQuestionsList = [
{
name: 'propertyType',
type: 'radio',
label: 'Purchase Type',
value: 'residential',
validators: [],
options: [
{ id: 'residential', value: 'residential', label: 'Purchase for you (Residential)', class: 'btn-choice--left' },
{ id: 'bytolet', value: 'bytolet', label: 'Purchase to rent (Buy-to-Let)', class: 'btn-choice--right' },
],
tooltip: '',
},
];
Desired result
export const extraQuestionsList = [
{
name: 'propertyType',
type: 'radio',
label: 'Purchase Type',
value: 'residential',
validators: [],
options: [
{ id: 'residential', value: 'residential', label: '<span class="hidden-xs">Purchase for you</span> (Residential)', class: 'btn-choice--left' },
{ id: 'bytolet', value: 'bytolet', label: '<span class="hidden-xs">Purchase to rent</span> (Buy-to-Let)', class: 'btn-choice--right' },
],
tooltip: '',
},
];
any help would be much appreciated.
Thanks in advance
Upvotes: 2
Views: 2000
Reputation: 601
You can create dynamic form as per your array and it should be in your HTML file as below.
<div *ngIf="extraQuestionsList[0].type == 'radio'">
<label>{{extraQuestionsList[0].label}}</label>
<div *ngFor="let item of extraQuestionsList[0].options" >
<input type="radio" name="extraQuestionsList[0].propertyType" [value]="item.residential" [ngClass]="item.class">
<span class="hidden-xs">{{item.label}}</span>
</div>
</div>
Also, remove const export in ts file so it can be treated as an array and you can use it to HTML template.
Upvotes: 0
Reputation: 1533
<li *ngFor="let opt of options">
<span class="hidden-xs">{{opt.id}}</span> {{opt.label}}
</li>
Upvotes: 1