Editing: I realized a few minutes later that my original answer missed the actual error. The definition of a polymer element is fine, but its use must be wrapped in a template so that you can do something like this:
<body> <template is="auto-binding"> <foo-bar url="/api/getdata" succCallback="{{func}}"></foo-bar> </template> <script> var scope = document.querySelector('template[is=auto-binding]'); scope.func = function (whatever) { console.log('yay!'); }; </script> </body>
The original answer below may be useful - especially where a callback is used.
Using the "publish" block instead of attributes ... er, attribute (now I understand that this was not the cause of the error):
<polymer-element name="foo-bar"> <template> <core-ajax id="ajax" method="POST" url="{{url}}" contentType="application/json" handleAs="json" on-core-response="{{handleResponse}}"></core-ajax> </template> <script> Polymer({ publish: { url: undefined, succCallback: undefined, }, ready: function(){ this.url = this.url || "some default"; this.succCallback = this.succCallback || function(){}; }, handleResponse: function(e){ var response = e.detail.response; if (response.status === 'success') { </script> </polymer-element>
I really was looking for the answer to the question: "Is this a template with traction in Polymer, or is it discouraged?" Since the use of callbacks is not even mentioned in Communication and Messaging , I am very curious.
source share