On 6 July 2017 at 00:13, Naga Sai A <[email protected]> wrote:
localStorage.setItem("temp", temp);
>
You're saving to the name "temp" an array of objects (from the variable
called temp - you confused matters by naming both the local storage and the
variable you're assigning to local storage with the same name so it is
unclear which is which when talking about it.
<my-app name="localStorage.getItem('temp')"></my-app>
>
Ignoring the fact that Polymer doesn't bind in this manner, you are
attempting to bind the "temp" you saved above which is an array of objects
into a property that requires a string.
You probably want something more like (assuming your syntax for
localStorage is correct - I haven't checked that part):
<script>
var saveMe = [
{ "name": "Name", "size": 40 },
{ "name": "Age", "size": 20 }
];
localStorage.setItem("saved", saveMe);
</script>
<dom-bind id="app">
<my-app name="[[temp]]"></my-app>
</dom-bind>
<script>
var app = document.getElementById("app");
app.temp = localStorage.getItem("saved");
</script>
--
A different approach might be to use app-localstorage-document (
https://www.webcomponents.org/element/PolymerElements/app-storage/elements/app-localstorage-document
):
<dom-bind id="app">
<app-localstorage-document key="saved"
value="{{temp}}"></app-localstorage-document>
<my-app name="[[_getAnItem(temp)]]"></my-app>
</dom-bind>
<script>
var app = document.getElementById("app");
// add _getAnItem() function to return something meaningful - you need a
string, but the example you provided in temp holds an array.
app._getAnItem = function(arr) {
return arr[0].name;
}
// if temp isn't loaded already we'll populate with something default
if (!Array.isArray(app.temp) || app.temp.length() === 0) {
app.temp = [
{ "name": "Name", "size": 40 },
{ "name": "Age", "size": 20 }
];
}
</script>
--
Daniel Llewellyn
Bowl Hat
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/polymer-dev/CABtuYwdgvA-H6G4ck3Ai2Ne531%3D0Yd2Um2aovphMAnZmRmFr6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.