avinash
avinash

Reputation: 163

Function property is not a function in Polymer

I am using the Polymer framework for my project in which I'm declaring a function callback in properties and trying to call it from another function. But on accessing it I'm getting an error:

Uncaught TypeError: this.callback is not a function

Please have a look into this.

Polymer({
  is: "parent-dom",
  properties: {
    people: {
      type: String,
      value: "df"
    },
    item: {
      type: String,
      value: "asdf",
      notify: true
    },
    callback: {
      type: Object,
      value: function(index) {
        console.log("Inside  callback function");
      }
    },

  },
  showTargetColorDialog: function(e) {
    this.callback("sadf");
  }
});

Upvotes: 0

Views: 852

Answers (1)

Andrew Ymaz
Andrew Ymaz

Reputation: 2203

Could you please provide more details about what you would like to achieve, since specify Polymer properties as functions it's not very common case?

So you could declare public methods on your element, like you did with showTargetColorDialog, and they will be accessible to be called like:

document.querySelector('parent-dom').showTargetColorDialog();

But again it's not very "Polymer way" to that.

To answer your original question, if you really need set callback as Polymer property (I'm still not sure why), but you could:

callback: {
  type: Object,
  value: function() {
    return function(index) {
        console.log("Inside callback function ", index);
    };
  }
},

And then you will be able to call this.callback('something');

Upvotes: 1

Related Questions