简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM