webmonkey
webmonkey

Reputation: 1093

Polymer: Call a behavior's property function in elements property values?

Recently I looked up Polymers app-localize-behavior and I saw they typed the localize() method as Function (see on GitHub):

excerpt from app-localize-behavior.html:

localize: {
  type: Function,
  computed: '__computeLocalize(language, resources, formats)'
},

This method works perfectly fine in data-bindings, like <div>{{localize('welcome')}}</div>, but how can I call this method from my elements properties? I try to do something like:

excerpt from my-element.html:

properties: {
    _pageTitle: {
      type: String,
      value: this.localize('welcome')
    }
}

But when I try this, I get a Uncaught TypeError: this.localize is not a function. Even in my ready method I need to call this.localize asynchronously as otherwise it isn't defined, too.

How could I solve that problem?

Thank you in advance!

Upvotes: 1

Views: 429

Answers (1)

tony19
tony19

Reputation: 138266

Use a computed property that invokes localize(...):

properties: {
  _pageTitle: {
    computed: 'localize("welcome")'
  }
}

demo

Upvotes: 2

Related Questions