Angular - Altering the presentation without altering the initial content

How can I format the data for viewing purposes while maintaining its original value?

I have created a method to format the value:

formatGroupName(groupAnalysisList: SelectItem[]) : any {
         groupAnalysisList.forEach((group:SelectItem)=>
             {group.label = group.label.toLowerCase().replace(/(?:^|\s)(?!da|de|do|e)\S/g, l
 => l.toUpperCase());
         });
         return groupAnalysisList;
 
     };

I am using this method in my HTML code :

[options]="formatGroupName(groupAnalysisList)"

For example, if I have a word like "DOLAR", I format it as "Dolar". However, I still want to keep the original value "DOLAR" in my TypeScript file.

Answer №1

Consider implementing a custom pipe for better functionality

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
   name: 'lower',
   pure: false
})
export class CustomTextTransformPipe implements PipeTransform {
  transform(inputText: string): any { 
     return inputText.toLowerCase().replace(/(?:^|\s)(?!da|de|do|e)\S/g, letter=> letter.toUpperCase());
   }
}

In your HTML, you can use the custom pipe like this:

<div>{{text | lower}}</div>

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

When the page is scrolled, the div is fixed in place and a class is dynamically added. Some issues may

Greetings everyone, I have a webpage with two floating divs - one is about 360px wide and the other has an auto width. As the page scrolls, the left div is assigned a class that fixes it to the screen, allowing the other div to scroll. This functionality w ...

Implementing CSS styles on iframe content in React

Is there a way to style the content loaded by an iframe in a React app using CSS? I'm facing an issue with loading external content into my app, as the styles are outdated and I want to customize them. See Example Below: (Please note that the src co ...

The content in ACF appears to be missing when displayed in the fancybox

I have configured ACF to appear in a fancybox. The fields are being pulled in (as I can see the hardcoded header information), but nothing from the ACF appears. I have linked it to call an ID, which is then associated with the section that should be displa ...

What is the best way to pass values between JSP Expression Language and Javascript?

I have a request object with the following content: List<Integer> list What is the best way to loop through this list using JavaScript? I am interested in obtaining the values of each element within the list. Note that these list values are not cu ...

Trouble with Chakra UI loading Images from local sources

I'm running into issues when trying to load local images using the Chakra UI library in combination with Next.js. <Image src="./homepage/footer/Black.svg" /> Here is the current folder structure: When checking my console, I see the f ...

What order do Node.js event queues, Promises, and setTimeout() operate in?

QUERY: When working with Node.js event queues, such as code like "new Promise((r) => setTimeout(r, t));", where exactly is the setTimeout() function evaluated? Is it immediate, in the microqueue for Promise resolutions, or elsewhere? INSIGHT ...

Guide on invoking an Angular 1.5 component with a button press

Having just started learning Typescript, I'm struggling to figure out how to call my Angular component "summaryReport" on a button click. Here's a snippet of my code: Let's say I have a button that should call my component when clicked with ...

Troubleshooting the pre-loader image loading problem

Apologies for bringing up a minor issue, but I'm struggling with this one. I added a pre-loader image to my page load using a simple method. You can find my page here Here is the HTML code for the Pre-loader image: <div class="se-pre-con">&l ...

Emulating a mouse click in jQuery/JavaScript on a webpage link

I am seeking a way to programmatically trigger a click on any link within a webpage using JavaScript. The challenge lies in ensuring that if the link has an 'onclick' event bound to it by another unknown JavaScript function, that event is trigger ...

Unleashing the Power of Google Apps Script Filters

Having some data in a Google Sheet, I am looking to filter it based on specific criteria and return corresponding values from another column. Additionally, I need to count the number of elements in the resulting column. Below is an example of the data: Sa ...

Utilizing the selectionStart-End method for textareas

Lately, I've been facing a frustrating issue where I am unable to find the starting and ending index of the selected text within a textarea. Whenever I try to access it, all I receive is 'undefined' like so: $('#myarea').selection ...

Executing a single command using Yargs triggers the execution of multiple other commands simultaneously

I've been diving into learning nodejs and yargs, and I decided to apply my knowledge by creating a command-line based note-taking app. The structure of my project involves two files: app.js and utils.js. When I run app.js, it imports the functions fr ...

Error message: The Slick Carousal encountered an unexpected problem - TypeError:undefined is not a function

I'm having an issue with a script for a Slick Carousel inside of some Ajax Tabs. I keep encountering the Uncaught TypeError: undefined is not a function error, but I'm unsure what exactly it's pointing to. $(document).ready(function(){ ...

Incorrect typings being output by rxjs map

combineLatest([of(1), of('test')]).pipe( map(([myNumber, myString]) => { return [myNumber, myString]; }), map(([myNewNumber, myNewString]) => { const test = myNewString.length; }) ); Property 'length' does not ...

Problem with integration of Bootstrap datetime picker in AngularJS directives

I am currently utilizing the Bootstrap Datetime picker to display data from a JSON file in calendar format. The data is first converted into the correct date format before being shown on the calendar, with both a To date and From date available. scope.onH ...

Puzzle of Pictures

Edited to include entire code I stumbled upon this intriguing image puzzle creator tool at [this link][1], but now I'm facing the challenge of modifying it so that when users click a "New Puzzle" button, the image changes to start a new puzzle. My ini ...

Creating a JSON object with nested arrays by adding items in JavaScript

I have an array of names and another one with JSON data accessible through a method. I attempted to carry out the following: let out = []; for (let i = 0; i < data.length; i++) { for (let j = 0; j < names.length; j++) { let feed = {[name ...

Automatically submit form in Javascript upon detecting a specific string in textarea

Just getting started with JS and I have a question that's been bugging me. I have a simple form set up like this: <form method="POST" action="foo.php"> <textarea name="inputBox123"></textarea> <input type="submit" value="Go" name ...

Is the username you want available?

I am facing a challenge in my registration form validation process where I need to verify the username input using javascript and flask in python, but the implementation is unclear to me. The requirement is to utilize $.get in the javascript segment along ...

What are the steps to troubleshoot a Node Package Manager library in Visual Studio Code?

I have created a Typescript library that I plan to use in various NodeJS projects. The source code is included in the NPM package, so when I install it in my projects, the source also gets added to the node_modules folder. Now, during debugging, I want to ...