Question

I want my element to have specific JavaScript API. For example like HTMLInputElement that have checked property, I want my element to have a property that you can only set binary values to it and I have callbacks to changes.

Était-ce utile?

La solution

This described in detail in the documentation.

Properties and methods are defined on the element's prototype using the Polymer() constructor.

Polymer('my-element', {
  name: 'Mohsen',
  isChecked: false,
  isCheckedChanged: function() {
    console.log('I am checked?', this.isChecked);
  },
  ...
});

To define a property as boolean, make sure to hint its type.

Use <prop>Changed watchers to be notified when the <prop> changes.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top