Function is getting called many times by using template interpolation?

前端 未结 1 1221
北恋
北恋 2020-12-03 16:15

Sorry for basic question, I am trying to understand the angular2 flow using basic example.

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

@Component({
    sel         


        
相关标签:
1条回答
  • 2020-12-03 16:44

    Binding to functions or methods in the template is discouraged because these functions are called every time change detection is run.

    You should at least cache results inside the function to avoid repeatedly recalculating potential expensive calculations.

    A better approach is to recalculate the result when properties change the result depends on, and assign the result to a property and bind to this property from the view instead.

    0 讨论(0)
提交回复
热议问题