Insert an ellipsis within the ngFor iteration

I'm currently working with a table in which the td elements are filled with data structured like this:

 <td style="width:15%">
      <span *ngFor="let org of rowData.organization; last as isLast">
         {{org?.name}}<span *ngIf="!isLast">,</span>
      </span>
</td>

My challenge is to add an ellipsis to the span element if its character length exceeds 15. I've tried using an ellipsis pipe, but it applies the ellipsis to every element in the array.

Current output: Assistant Surgeon, Assistant Surgeon Pedia..., Assistant Surgeon techn..., Assistant Surgeon

Desired output: Assistant Surgeon, Assistant Surgeon Pediatrician, Assistant Surgeon techn...

Any suggestions on how to achieve this specific ellipsis implementation?

Answer №1

Check out this solution:

<div style="width:50%">
  <ul *ngFor="let item of data.items; let i=index">
     <li *ngIf="i % 2 === 0">{{ item }}</li>
  </ul>
</div>

This code snippet utilizes Angular's structural directives to display items in a list conditionally based on their index position. It only displays items with an even index.

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

Verify if the currentRoute begins with a specific text pattern (such as something/something/*...) in Angular

I need to prevent a loader from appearing on certain screens, so I used ngIf on routes where the loader is not necessary. Here's the code snippet from app.component.ts : <router-outlet> <app-spinner></app-spinner> <ngx-ui-load ...

Upon closing the browser, the Angular ngx-cookie-service data disappears

Currently, I am working on setting a cookie using ngx-cookie-service so that I can retrieve it later as needed. Everything seems to be functioning properly as the code works well when refreshing the page, and the cookie is visible in Chrome developer tool ...

Angular messaging service error TS2769: There is no overload that fits this call

Currently, I am attempting to utilize a messenger service to send products to the cart component. Within the 'Product' class, there are various product attributes stored. Although I managed to successfully log the product to the console in the ca ...

A guide to incorporating border radius to images within a composite image with sharp.js in Node.js

In my Node.js project, I am using the sharp library to combine a collection of images into a single image. Although I have successfully created the composite image, I now need to add a border radius to each of the images in the grid. Here is the code snip ...

Tips for dynamically updating localeData and LOCALE_ID for i18n websites during the build process in Angular 9

I am currently developing an application that needs to support multiple languages, specifically up to 20 different languages. The default language set for the application is en-US. The translated versions are generated successfully during the build proces ...

Is there an alternative method to incorporate the 'environment.ts' file into a JSON file?

In my Angular application, I need to import assets based on the env configuration. I am attempting to extract the patch information from environment.ts and save it into my assets as a json file. However, I am unsure of the proper method to accomplish this. ...

How do I manage two components on the same routing level in Angular with query parameters?

I am working with Angular and have two components placed at the same level of routing, both in the root directory. { path: '', component: HomeComponent }, { path: '', component: SearchComponent }, My challenge is to mak ...

Issue with Angular 2 directive update detection; unresolved directive not refreshing

I have created an Angular 2 application that displays a number which can be either negative or positive. In order to change the font color to red when the value is negative, I've implemented a directive. This number gets updated constantly through an ...

What is the best way to iterate through a collection of two or more arrays in order to determine the total length of all

https://i.stack.imgur.com/PpFlB.pngI currently have multiple Arrays containing various inputs this.listNumber = [ { "GenericQuestions": [ { "input": "long", }, { "input": & ...

Guide to setting up a one-to-many self relation entry in Prisma

I am facing a challenge with a simple schema model that includes one-to-many self relations. In this scenario, my goal is to create a parent entity along with its children in a single transaction. How can I accomplish this task effectively? data-model Y{ ...

In Typescript, which kind of event is suitable for MouseEvent<HTMLDivElement>?

My goal is to close the modal when clicking outside the div element. Take a look at my code below. // The onClose function is a setState(false) function. import { useRef, useEffect } from 'hooks' import { MouseEvent } from 'react' imp ...

Dependency error reported in Angular update

Encountering an issue with updating my angular project - when running ng update @angular/core, I receive the following error message: Using package manager: 'npm' Collecting installed dependencies... Found 41 dependencies. Fetching dependency met ...

Using SignalR to implement CRUD operations within a Hub or Controller

I have been working on an Angular app that is built on top of an ASP.NET MVC application. In this project, I have a Dashboard where I showcase Average and Total numbers that are altered during Create / Update / Delete events. Usually, these events are hand ...

Receiving data from a service in Angular 2 with rxjs subscribe throws an error: it is not a

I've recently started working with Angular and I'm encountering an issue when trying to pass the _newArray to my child component using a shared service. Service fetchData(): Observable < any > { return forkJoin(this.fetchQuestions(), th ...

The Angular module loaded lazily encountered a 401 error

Currently, I am working on an Angular application that consists of multiple lazy-loaded modules built using Angular CLI. The resources (JS, CSS, and HTML) within these modules require authorization, which is managed through a cookie system. If a user attem ...

What is the best way to combine API calls using rxJs subscribe and map in Angular?

Currently, I am executing multiple API requests. The first one is responsible for creating a User, while the second handles Team creation. Upon creating a User, an essential piece of information called UserId is returned, which is crucial for the Team cre ...

What is the best way to decide on a method's visibility depending on who is calling

I am curious about the best approach for providing methods with "privileged access" that can only be called by specific object types. For instance, if you have a Bank object with a collection of Accounts, you may want to allow the Bank object to call acco ...

Strategies for modifying the title attribute within an <a> tag upon Angular click event

I am attempting to dynamically change the title attribute within an anchor tag upon clicking it. The goal is for the title attribute to toggle between two states each time it is clicked. Currently, I am able to change the title attribute successfully upon ...

Is the Angular maxlength parameter causing issues with user input?

Previously, the old ng-maxlength="5" would trigger a field error but allow user input to continue. Now, with maxlength="5", it seems that input is being prevented altogether. I have novalidate on my form - could Angular be causing this? Should input be all ...

The module 'Express' does not have a public member named 'SessionData' available for export

I am encountering an issue while working on my TypeScript project. I am not sure where the error is originating from, especially since nothing has been changed since the last time I worked on it. node_modules/connect-mongo/src/types.d.ts:113:66 - error TS ...