dynamic padding style based on number of elements in array

Is there a way to set a padding-top of 10px only if the length of model.leaseTransactionDto.wagLeaseLandlordDto is greater than 1?

Can someone provide the correct syntax for conditionally setting padding based on the length? Thank you.

#sample code

<div *ngFor="let landlord of model.leaseTransactionDto.wagLeaseLandlordDto; let i = index"
     [style.padding-top.px]="model.leaseTransactionDto.wagLeaseLandlordDto.length > 1 ? 10 : 0"
     style="font-size: 12px;text-overflow: ellipsis;overflow-x: hidden;">
    <div class="primary-color" matTooltip="{{landlord.landLordEmail}}"
         style="text-overflow: ellipsis; overflow-x: hidden;"
         *ngIf="landlord.landLordEmail">{{landlord.landLordEmail}}</div>
</div>

Answer №1

You have the option to conditionally set the ngStyle based on the length of

model.leaseTransactionDto.wagLeaseLandlordDto
:

<div class="primary-color" 
    [ngStyle]=" {'padding-top': 
    model.leaseTransactionDto.wagLeaseLandlordDto.length > 1 ? '10px' : ''}
    
    matTooltip="{{landlord.landLordEmail}}" *ngIf="landlord.landLordEmail">
    {{landlord.landLordEmail}}
</div>

Answer №2

Applying ngstyle property based on a condition

<div *ngFor="let landlord of model.leaseTransactionDto.wagLeaseLandlordDto; let i = index" [style.padding-top]="model.leaseTransactionDto.wagLeaseLandlordDto.length > 1 ? '10px' : '0px'">
     <div class="primary-color" style="text-overflow: ellipsis;overflow-x: hidden;font-size: 12px;" matTooltip="{{landlord.landLordEmail}}" *ngIf="landlord.landLordEmail">{{landlord.landLordEmail}}</div>
</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

Dividing a TypeScript NPM package into separate files while keeping internal components secure

I have developed an NPM package using TypeScript specifically for Node.js applications. The challenge I am facing is that my classes contain internal methods that should not be accessible outside of the package, yet I can't mark them as private since ...

Using webpack to generate sourcemaps for converting Typescript to Babel

Sharing code snippets from ts-loader problems may be more suitable in this context: Is there a way to transfer TypeScript sourcemaps to Babel so that the final sourcemap points to the original file rather than the compiled TypeScript one? Let's take ...

Challenge encountered with implementing Next-Auth's authorize function in TypeScript

Encountering a type error in the authorize function while using NextAuth with CredentialsProvider export const authOptions : NextAuthOptions ={ session : { strategy: "jwt" }, providers : [ CredentialsProvider({ async authorize( c ...

React: Issue with passing arguments to redux action hooks

In my React application, I have implemented Redux-Toolkit to manage reducers and actions with slices. I am currently working on creating actions that can update and delete values from the store, requiring arguments for their usage. To achieve this, I have ...

Time for Angular Component Observable Bindings

I came across a similar question elsewhere, but unfortunately, it was left unanswered 1. In my service, I have a scenario where I check local storage for a specific value. If the value exists, I set it as the next value for the Subject; if not, I make an ...

Angular encountered an ERROR of type TypeError where it cannot access properties that are undefined when trying to read the 'title'

I designed a form and I am trying to save the information entered. However, when I attempt to use the save method, an error keeps popping up. How can I troubleshoot this issue and successfully save the data from the form? ...

Tips for testing the window.innerWidth property in Angular 8?

I am relatively new to Angular and TDD. Right now, I am attempting to test a function that is called during a resize event. Below is the code snippet in question: header.component.ts @Component({ selector: 'app-header', templateUrl: &ap ...

Unable to perform type casting in Typescript

I recently dived into the world of TypeScript by picking up a book titled Typescript Revealed (Published in February 2013). Chapter 2 caught my attention with a section on "Casts" featuring an intriguing example: var a : int = <int>SomeNumberAsAStri ...

Obtain the parameters of a function within another function that includes a dynamic generic

I am attempting to extract a specific parameter from the second parameter of a function, which is an object. From this object, I want to access the "onSuccess" function (which is optional but needed when requested), and then retrieve the first dynamic para ...

Enhance your text in TextInput by incorporating newline characters with advanced editing features

I'm encountering an issue with my Textarea component that handles Markdown headers: type TextareaProps = { initValue: string; style?: StyleProp<TextStyle>; onChange?: (value: string) => void; }; type OnChangeFun = NativeSynthetic ...

Hold off on proceeding until the subscription loop has finished

Is there a way to verify that all results have been successfully pushed to nodesToExpand after running the for loop? The getFilterResult function is being called via an HTTP request in the nodeService service. for(var step in paths) { this.nodeSe ...

Error in ReactJS VSCode while integrating Cypress testing: The name 'cy' cannot be found

Currently working on a ReactJS Typescript project using NPM and VSCode. Despite all my Cypress tests running smoothly, I am encountering a syntax error in VSCode: Error: Cannot find name 'cy' Any ideas on how to resolve this issue? Attempted th ...

Is it planned to include StencilJS as a development choice in Ionic?

I'm curious about the potential adoption of Stencil JS for developing mobile apps within the Ionic framework. When I mention "an option for developing," I'm referring to frameworks like NativeScript where developers can choose between Angular + ...

Enhance Express Middleware with Typescript for advanced functionality

Currently in the process of developing a REST API using Express and Typescript, I am encountering difficulties when trying to extend the Request/Response objects of Express. Although my IDE shows no errors, Typescript throws TS2339 Errors during compilati ...

Is there a way to remove a dynamically rendered component from a list?

Whenever I click a button, the same component is dynamically rendered on top of the list. But now, I need to implement a feature where users can delete any component from the list by clicking a cancel button associated with each component. Here's my ...

Is there a way to duplicate content (also known as *ngFor) without using a surrounding element?

I am working on an Angular 4 component that utilizes a 2d array structure. I have an array of sections, each containing an array of links. My goal is to display them in a flat format: <ul> <div *ngFor="let section of all_sections"> <l ...

Having trouble loading the DOM element within the child component

An issue has arisen with Angular 4.4.6 regarding the access of a DOM element by ID from a different component. Within my component, I aim to display a Google Maps for specific purposes. Following the examples given in the API, I include the following code ...

Tips for personalizing the ngx-bootstrap datepicker

I am looking to enhance the ngx-bootstrap datepicker popup by adding a link or button within the calendar to select dates with a single click. I have been exploring ways to customize the datepicker without success. Currently, my project is built using Angu ...

Having trouble capturing emitted events from a child component in Angular 2+?

I have a question as a beginner. I'm trying to send a message from the child component to the parent component but for some reason, it's not working. app.component.html <app-cart-component> [items]="rootItems" (outputItems)=&quo ...

An issue occurred when retrieving the input value during a (change) event within a nested *ngFor loop in Angular

Within my table, I have implemented a nested loop using the *ngFor directive: <tbody> <tr *ngFor="let dept of salesTarget; let i = index"> <td>{{dept.dept}}</td> <td *ngFor="let month of monthList; ...