javascript - Data binding in Polymer - function is being removed from bound object -


i'm encountering issue binding object contains function angular polymer 1.0. function not being passed through target object in custom element. here simplified code sample:

the custom element has single property named myprop:

<script>         polymer({         is: 'my-custom-element',         properties: {             myprop: object         },         attached: function () {             var x = this.myprop.x;       //this ok             this.myprop.myfunc();        //myfunc not defined!             }     });  </script> 

here html:

<div ng-app="myapp">     <div ng-controller="myctrl">         <my-custom-element myprop="{{myobject}}"></my-custom-element>     </div> </div>     

and here angular controller:

<script>     angular.module("myapp", []).controller("myctrl", function ($scope) {             $scope.myobject= {           x: 4,           myfunc: function() {              //function body           }          }         });     </script> 

why isn't function available in custom element?

as documented here: https://github.com/polymer/polymer/blob/3e96425bf0e0ba49b5f1f2fd2b6008e45a206692/primer.md#attribute-deserialization

... objects passed polymer elements being passed through json.stringify , json.parse (depending on variable type).

functions stripped out json.stringify - checkout out sample...

console.log( json.stringify({x:123,y:function(){ return 123; }}) ); // outputs: {"x":123} 

i believe offending line in source...

https://github.com/polymer/polymer/blob/3b0d10b4da804703d493da7bd0b5c22fc6f7b173/src/micro/attributes.html#l232

... , comments nearby suggest possibility change behavior...

users may override method on polymer element prototypes provide serialization custom types


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -