One-time binding does not work with function

I have an Angular function where I register a value

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

and here in the html code

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

Accordingly, the value should be displayed once and never again. But when I scroll, the value is continuously printed on the console.

Where am I wrong?

+7
angularjs
source share
1 answer

According to the angular documentation ,

One-time binding expressions store the value of the expression at the end of the digest cycle, if that value is not undefined

Your function returns nothing, so the value is undefined. getFormattedDate needs to return something for Angular to recognize a one-time binding.

+15
source share

All Articles