javascript - Technical reason of data loss of variable -


I am using polymers.

A polymer component is bound to a script which handles its logic:

  & lt; Polymer-element name = "my-component" & gt; & Lt; Templates & gt; & Lt; / Template & gt; & Lt; Script src = "my-component.js" & gt; & Lt; / Script & gt; & Lt; / Polymer element & gt;  

is generated by passing the object near the polymer function. It describes the object component and should have at least one property named ready . This is a function that produces each component, for example when the script was first for & amp; Is called; It is used every time after its initial call.

This is my my-component.js

  var timeline; Function Load Timeline () {Return System.import ('Balance / Timeline / Timeline Module'). Then (function (tm) {timeline = TM.service;}); }; Load Timeline () Then (function () {var element = (function var component; return {ready: function} {var self = this; component = this; methodThatUtilizesTimelineModule ();}}}) (); polymers ('day-view', element );}) Catch (function (e) {console.error (e)});  

My problem is now, that everything works well as long as the script is called for the first time. Hoveryvery, as soon as I leave the component and call someone else, if it comes under the above script, timeline will be undefined and then used it If I call loadTimeline () from within the component object

then I know that this issue is that the value of my variable is lost whenever I leave that script and leave that component, but I do not know. Why is it

I am very new to the polymer, but perhaps you can experiment globally?

  & lt; Polymer-element name = "app-global" & gt; & Lt; Script & gt; (Function () {// These variables are shared with all examples of the app-globals ware firstname = 'John'; var lastName = 'Smith'; Polymers ({ready: function ()} {// Global values Copy the properties of example .firstName = firstname; this.lastName = lastName;}});}) (); & Lt; / Script & gt; & Lt; / Polymer element & gt;  

Then use it like this

  & lt; Polymer-element name = "my-component" & gt; & Lt; Templates & gt; & Lt; App-global id = "globe" & gt; & Lt; / App-globals & gt; & Lt; Div id = "firstname" & gt; {{$. Globals.firstName}} & lt; / Div & gt; & Lt; Div id = "lastname" & gt; {{$ Globals.lastName}} & lt; / Div & gt; & Lt; / Template & gt; & Lt; Script & gt; Polymer ({ready: function () {console.log ('last name:' + this. $ Globals.lastName);}}); & Lt; / Script & gt; & Lt; / Polymer element & gt; View the API Developer Guide at  


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -