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...
... , comments nearby suggest possibility change behavior...
users may override method on polymer element prototypes provide serialization custom types
Comments
Post a Comment