1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular method call in a template expression 4 times

Discussão em 'Angular' iniciado por Hoi Tran Van, Junho 27, 2025.

  1. Hoi Tran Van

    Hoi Tran Van Guest

    here is my code:

    import { Component } from '@angular/core';

    @Component({
    selector: 'app-root',
    standalone: true,
    template: `
    <h1>{{getTitle()}}</h1>
    `,
    styleUrl: './app.component.css'
    })
    export class AppComponent {
    title = 'app-angu-tur';

    public getTitle():string {
    console.log("log get title");
    return this.title;
    }
    }


    I created an angular project using ng new command, I also changed the code a little bit to test and I checked in devtool and saw that the console log function was printed 4 times. What I am wondering is why it is printing 4 times, I thought it would print maximum 2 times ? Thanks for reading

    Continue reading...

Compartilhe esta Página