1

I have this template dom-if using Polymer 1.X, and it is not working.

It is supposed to display 'Loading' when requirement.allLoaded is false and display the real content when requirement.allLoaded is true.

I switch the state of this variable in my test function. But it doesn't take effects.

//Properties
requirement: {
    type:Object,
    value: {
        allLoaded: false,
        tagsLoaded: false
    }
}
//Test function
_testButton: function(){
    console.log(this.requirement);
    this.requirement.allLoaded = !this.requirement.allLoaded;
    console.log(this.requirement);

},
<div id="modal-content">
    <template is="dom-if" if={{!requirement.allLoaded}}>
        <p>Loading</p>
    </template>
    <template is="dom-if" if={{requirement.allLoaded}}>
        <iron-pages selected="[[selectedTab]]" attr-for-selected="name" role="main">
            <details-tab name="details"></details-tab>
            <bar-chart-tab name="barchart"></bar-chart-tab>
            <live-data-tab name="livedata" shared-info='{{sharedInfo}}'></live-data-tab>
        </iron-pages>
    </template>
</div>

Note: I already used this structure to display/not display things in other project (with Polymer 2) and it was working.

kahveci
  • 1,429
  • 9
  • 23
NeitoFR
  • 716
  • 1
  • 11
  • 23

2 Answers2

0

Is it only the change that does not work? I.e. it shows correctly on load?

Try notifying Polymer of the change: this.requirement.allLoaded = !this.requirement.allLoaded; this.notifyPath('requirement.allLoaded');

Erik Lumme
  • 5,202
  • 13
  • 27
  • Well with that line it works :), thanks a lot, the subquestion is why is it working in the other project. Have a nice day thank you again – NeitoFR Apr 05 '18 at 10:13
  • Not sure, Polymer 2.0 did many changes in the data system, but I'm not sure what caused this difference. https://www.polymer-project.org/2.0/docs/about_20#data-system – Erik Lumme Apr 05 '18 at 10:47
0

You could also use this.set('property.subProperty', value) for Observable Changes.
In your case, that's this.set('requirement.allLoaded', !this.requirement.allLoaded);

Arnold
  • 311
  • 4
  • 9