2016-08-17 73 views
2

是否为ng-show的聚合物等效物?这里是什么,我想转换一个片段例如:聚合物相当于ng-show?

<h1>Greeting</h1> 
<div ng-show="authenticated"> 
    <p>The ID is {{controller.greeting.id}}</p> 
    <p>The content is {{controller.greeting.content}}</p> 
</div> 
<div ng-show="!authenticated"> 
    <p>Login to see your greeting</p> 
</div> 

回答

2

dom-if在这里没有必要。只需使用$=(属性绑定)来添加/删除hidden属性。

<style> 
[hidden] { 
    display:none; 
} 
</style> 

<h1>Greeting</h1> 
<div hidden$=[[!authenticated]]> 
    <p>The ID is {{controller.greeting.id}}</p> 
    <p>The content is {{controller.greeting.content}}</p> 
</div> 
<div hidden$=[[authenticated]]> 
    <p>Login to see your greeting</p> 
</div> 

使用dom-if作出关于你不想被渲染,而不只是隐藏的代码块的决定。

1

我想你可以使用dom-if有条件保持所需的HTML中DOM树。 properties应该在组件的properties中定义。

<template is="dom-if" if="{{authenticated}}"> 
    <p>The ID is {{controller.greeting.id}}</p> 
    <p>The content is {{controller.greeting.content}}</p> 
</template> 
<template is="dom-if" if="{{!authenticated}}"> 
    <p>Login to see your greeting</p> 
</template> 
+1

dom-if相当于ng-if! –