Incorporating HTML code within a .ts file: a basic guide

I'm relatively new to Angular, but I've been given a project that's built with Angular.

As I examine the .ts file containing the list of property types, I need to wrap a span around the label text. Is this doable?

Here is the current list within the .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: '',
  },
];

Here's how I want it to look:

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 assistance on this matter would be greatly appreciated.

Thank you in advance.

Answer №1

<ul *ngFor="let option of options">
  <span class="hidden-xs">{{option.id}}</span> {{option.label}}
</ul>

Answer №2

If you want to create a dynamic form based on an array, you need to include the following code in your HTML file:

<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>

Additionally, make sure to remove const export in your TypeScript file so that the array can be accessed and utilized in your HTML template.

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

Develop an Angular application with a customized URL path that utilizes a ServiceWorker

I am currently working on an Angular 10 application. It utilizes the Angular "service worker" to transform into a PWA. Once the app is compiled, it resides in "c:\-website-folder-\ng-app\dist". Users can access the app through a URL like: ...

Tips for relocating a switcher button using Ant Design Drawer in a React application

*I'm faced with a challenge in my React project where I need to synchronize the movement of a div (switcher-btn) and an Ant Design Drawer. Whenever the Drawer is opened, I want the switcher-btn to move along with it. Below is the code snippet I'v ...

Refreshing an Angular page when navigating to a child route

I implemented lazy loading of modules in the following way: { path: 'main', data: {title: ' - '}, component: LandingComponent, resolve: { images: RouteResolverService }, children: [ { path: '', redirectTo: 'home&apo ...

Converting Typescript fat arrow syntax to regular Javascript syntax

I recently started learning typescript and I'm having trouble understanding the => arrow function. Could someone clarify the meaning of this JavaScript code snippet for me: this.dropDownFilter = values => values.filter(option => option.value ...

Tips for sending TypeScript objects to Vue components

Currently, I am working with the Vue 2 composition API plugin along with typescript version 3.9.7. In my project, I have a simple type defined as Usp which I want to pass as a prop to a component named UspSection. The structure of the USP type is outline ...

Unable to transfer object from Angular service to controller

I am currently utilizing a service to make a $http.get request for my object and then transfer it to my controller. Although the custom service (getService) successfully retrieves the data object and saves it in the responseObj.Announcement variable when ...

Angular 8 Refresh Token Implementation

I am currently working on an Angular 8 app that is integrated with .NET Core. My goal is to find a way to refresh a JWT token within the application. Within the integration, users are able to validate and receive a token which expires after 30 minutes. T ...

Steps for retrieving multiple documents from Firestore within a cloud function

In my cloud function, I have set up a trigger that activates on document write. This function is designed to check multiple documents based on the trigger and execute if/else statements accordingly. I have developed a method that retrieves all documents u ...

Unleashing the Potential: Integrating a Scanner Device with

Currently, I'm facing the challenge of integrating a Scanner device with my Angular application. On one of the pages dedicated to scanning, users are able to view an alert indicating the connection status of the Scanner as well as any scanned document ...

When compiling for production, I am encountering an issue where the hashed files are resulting in 404 errors for users when they try to refresh. I am unsure of the best

My Angular app is hosted on GCP storage. When I use the command ng build --prod --base-href . --output-path ~/Dev/GCP/, everything works perfectly except for one issue. If a user refreshes to get new content, they encounter 404 errors on CSS and JavaScript ...

Implementing intelligent parameter type enforcement according to configuration settings

I can't decide on a name for this concept, so please be patient while I explain it. There are three configuration objects: const configA = { type: 'A' as const, getPath: (query: { foo: string }) => `/${query.foo}` } const config ...

ag-grid provides unique filter options for custom date filtering in Angular 2

Currently, I am attempting to assign new options to a date column field by using the following method. However, these new options are not being displayed in the grid. let dateValues = ["equals", "inRange","quarter1","quarter2","quarter3","quarter4"]; { ...

What is the best way to alter the Date format in Typescript?

Within my response, the field createdate: "2019-04-19T15:47:48.000+0000" is of type Date. I am looking to display it in my grid with a different format such as createdate: "19/04/2019, 18:47:48" while maintaining its original data type. To achieve this, I ...

The specified format of `x-access-token` does not match the required type `AxiosRequestHeaders | undefined`

I am encountering an issue while trying to add an authHeader to the "Service". The error message displayed is: Type '{ 'x-access-token': any; } | { 'x-access-token'?: undefined; }' is not assignable to type 'AxiosRequest ...

Tips for troubleshooting issues with the Angular CLI development server

When I run ng serve from the Angular CLI in development, I expect my application to be served locally with live reloading. Usually, I see a single [WDS] Live Reloading enabled. message in the console after loading my app in the browser. Issue at Hand: La ...

Search for specific item within an array of objects

Working on an Angular project, I am attempting to remove an object from an array. To achieve this, I need to filter the array and then update the storage (specifically, capacitor/storage) with the modified array. Here is my function: deleteArticle(id: str ...

What is the process for defining a state using React Native and TypeScript?

Recently, I've embarked on my journey with React Native and decided to incorporate TypeScript into my development process. As I attempted to set my state, an error popped up that reads as follows: An issue arose while trying to assign the argument &a ...

Tips for including new items in an array within a subscribe valueChanges in Angular

What is the process for extracting values from a reactive form and storing them in an array when the form is valid? My application features dynamic forms with various fields that appear dynamically. retrieveFormValues(){ let valuesArray = []; this.fo ...

JavaScript Date() function misinterpreting Unix timestamp

When creating the date using a timestamp retrieved from Firebase, I use the following code: let da = new Date(item.date.day); I have double-checked that item.date.day is indeed a timestamp and the correct one at that. However, regardless of the actual t ...

Learn the process of transferring a complete JSON object into another object using Angular

I'm having trouble inserting one object into another. My JSON object is multidimensional, like this: { "item1":{ "key":"Value", "key":"Value" }, "item2":{ "key ...