简体   繁体   中英

tap:AMP.setState not working intermittently

tap:AMP.setState not working at times but it works when i reload the page.

<div class="padTop20">
    <a [class]="model.nextStep.expand ? 'hide' : 'show'" role="button" class="show" on="tap:AMP.setState({model:{nextStep:{expand: true}}})" id="showmore">Show more</a>
    <a [class]="model.nextStep.expand ? 'show' : 'hide'" role="button" class="hide" on="tap:AMP.setState({model:{nextStep:{expand: false}}})" id="showless">Show less</a>
</div>

Here's my default state:

<amp-state id="model">
        <script type="application/json">
            {              
               "nextStep":{  
                  "expand":false
               }
            }
        </script>
    </amp-state>

Is it something because of network that makes it behave like this?? Appreciate for any help! thanks!

You should try;

[class]="(model.nextStep.expand == 'true') ? 'hide' : 'show'"

and

[class]="(model.nextStep.expand == 'false') ? 'show' : 'hide'"

On page load, as soon as the DOM is loaded, your initial state (false) is fired and [class] is rendered because of amp-bind.

You didn't post much in terms of any console errors or validation errors you might be facing with AMP (which will affect the functionality if you did something weird/wrong)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM