Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Angular-2 : Is function call instead in-line boolean condition impact on performance?

I am working with user authorization and going to disabled button as per condition.

I have already implemented logic, but I wants to know if I use function instead of In-line logic may impact on performance or not?

My logic are as below:

In line:

<button type="button" class="btn btn-primary" [disabled]="!ApplicationManager.Model.CanModifyFramework && ((selectedPage.Scope!='0' && !ApplicationManager.Model.CanModifyConfiguration) || (selectedPage.Scope=='0' && ApplicationManager.Model.CanModifyConfiguration))">Save & Close</button>

Function:

<button type="button" class="btn btn-primary" [disabled]="!GetUserAccessability(selectedPage.Scope)">Save & Close</button>

public GetUserAccessability(scope: any): boolean {
    let result: boolean = false;

    if (this.Model.CanModifyFramework) {
        result = true;
    }
    else if (this.Model.CanModifyConfiguration && scope>0)
    {
        result=true
    }       

    return result;
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Angular change detection is most efficient when you bind to a field instead of a method.

It's better to use an observable or an event that notifies on changes, instead of polling, and then update the field in the event handler.

Also a good way is to use ChangeDetectionStrategy.OnPush and bind to an observable. The | async pipe will call ChangeDetectorRef.markForCheck() every time a new value is emitted.

The worst thing you can do is binding to a method that returns a new array of object instance for each call. This will bring your application to its knees. Your method doesn't do that and therefore isn't that bad. Binding to a field or Observable is IMHO still the better way.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda