点击:AMP.setState不能间歇工作

时间:2018-05-29 05:09:35

标签: accelerated-mobile-page google-amp

点击: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>

这是我的默认状态:

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

是不是因为网络让它表现得像这样?感谢任何帮助!谢谢!

1 个答案:

答案 0 :(得分:0)

您应该尝试;

[class] =“(model.nextStep.expand =='true')?'隐藏':'显示'”

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

在页面加载时,一旦加载DOM,就会触发您的初始状态(false),并且由于amp-bind而呈现[class]。

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