Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Concatenating strings in angular template performance

I wonder if it's a bad pattern and a performance issue if we concatenate strings consisting on hardcoded text and field values in the angular template.

I.e. - does the first component rerun string concatenation each time change detection cycle runs? Should it be always replaced by the second one?

@Component({
    selector: 'app-example',
    template:
        `
        <div [ngClass]="'color'-colorName">
        </div>
    `
})
export class ExampleComponent {

    @Input() colorName: string;

}

@Component({
    selector: 'app-example',
    template:
        `
        <div [ngClass]="className">
        </div>
    `
})
export class ExampleComponent {
    
    className: string;

    @Input() set colorName(value: string) {
        this.className = 'color' + value;
    }

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I dare to say you won't see any performance differences in those examples. Concatenating strings is very performant. It does not matter whether that happens in the template or somewhere else, since the template gets compiled into pretty simple js code.

I do not see pre-computing the value as a performance benefit. There are much more important performance techniques such as using OnPush change detection and code splitting.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!