angularjsone-time-binding

One time binding not working with function


I have an Angular function where i log a value

$scope.getFormattedDate = function(date){
    console.log(date)
}

and here in the html code

span {{::getFormattedDate('hello')}}

According to this the value should get rendered once and never again. But when i scroll, the value gets printed in the console continuously.

Where am i going wrong?


Solution

  • According to Angular documentation,

    One-time binding expressions will retain the value of the expression at the end of the digest cycle as long as that value is not undefined

    Your function is not returning anything, so the value is undefined. getFormattedDate needs to return something for Angular recognize the one-time binding.