简体   繁体   English

tap:AMP.setState不能间歇性地工作

[英]tap:AMP.setState not working intermittently

tap:AMP.setState not working at times but it works when i reload the page. tap:AMP.setState有时不起作用,但是当我重新加载页面时它起作用。

<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'" [class] =“(model.nextStep.expand =='true')?'隐藏':'显示'”

and

[class]="(model.nextStep.expand == 'false') ? 'show' : 'hide'" [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. 在页面加载时,一旦加载DOM,就会触发您的初始状态(false),并由于amp-bind而呈现[class]。

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) 关于AMP可能遇到的任何控制台错误或验证错误,您发布的内容不多(如果您做的事情很奇怪/错误,将会影响功能)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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