Docs (4.0.0)
class Binding method

strf

Adds a filter, to include the bound value in a formatted string.

strf(format: string): Binding<LazyString>

Summary

This method uses the bound value as a single placeholder value in a formatted string (as if strf() is used with the provided format string, and the current value of the binding).

Note that you can also use bound.strf() or Binding.asString() to create formatted string bindings.

  • Use Binding.asString() for single values such as numbers, e.g. bound.number("price").asString(".2f").
  • Use bound.strf() to include multiple bound values in a single string.
  • The bound.strf() function adds a slight overhead, since it creates an additional binding.

Parameters

  • format — The format string, as if passed to strf(); may include one placeholder, for the bound value

Return value

A new binding, typed as a string

Example

// A label with text that includes a bound number property
ui.label(
  bound("nEmails")
    .strf("You have %n email#{/s}")
)

// Same as the following, at a slight overhead
ui.label(
  bound.strf("You have %n email#{/s}", "nEmails")
)

Related