试图让 dom-if 工作
Trying to get a dom-if to work
我正在尝试使用纸张切换按钮删除和添加模板内容。但是,即使发生切换,我也看不到模板的内容。
使用的代码如下:
.飞镖
PolymerRegister( 'test-if-form' )
class TestIfForm extends PolymerElement {
TestIfForm.created( ) : super.created( );
@Property( observer: 'togglerChanged' )
//@property
bool toggler = false;
@reflectable
void toggleNormalChangedEvent( event, [_] ) {
toggler = !toggler;
print( 'toggler $toggler' );
}
@reflectable
void togglerChanged( newValue, oldValue ) {
print( 'new value $newValue' );
if ( newValue ) {
toggler = !toggler;
}
}
}
.html
<dom-module id = "test-if-form">
<template>
<div
class = "layout horizontal center-justified"
id = "normal-changed-toggler-container">
<span class = "margin-rt-5px">Normal</span>
<paper-toggle-button
required
on-change = "toggleNormalChangedEvent"
id = "togglerBtn">Changed
</paper-toggle-button>
<div>
<hr>
</div>
</div>
<br>
<template is = "dom-if"
if = "{{toggler}}"
restamp>
<div>I am now visible</div>
</template>
</template>
</dom-module>
嵌套的 div 元素的内容永远不可见。好像没有调用if?
感谢您的帮助。
toggler = !toggler;
应该是
set('toggler', !toggler);
我正在尝试使用纸张切换按钮删除和添加模板内容。但是,即使发生切换,我也看不到模板的内容。
使用的代码如下:
.飞镖
PolymerRegister( 'test-if-form' )
class TestIfForm extends PolymerElement {
TestIfForm.created( ) : super.created( );
@Property( observer: 'togglerChanged' )
//@property
bool toggler = false;
@reflectable
void toggleNormalChangedEvent( event, [_] ) {
toggler = !toggler;
print( 'toggler $toggler' );
}
@reflectable
void togglerChanged( newValue, oldValue ) {
print( 'new value $newValue' );
if ( newValue ) {
toggler = !toggler;
}
}
}
.html
<dom-module id = "test-if-form">
<template>
<div
class = "layout horizontal center-justified"
id = "normal-changed-toggler-container">
<span class = "margin-rt-5px">Normal</span>
<paper-toggle-button
required
on-change = "toggleNormalChangedEvent"
id = "togglerBtn">Changed
</paper-toggle-button>
<div>
<hr>
</div>
</div>
<br>
<template is = "dom-if"
if = "{{toggler}}"
restamp>
<div>I am now visible</div>
</template>
</template>
</dom-module>
嵌套的 div 元素的内容永远不可见。好像没有调用if?
感谢您的帮助。
toggler = !toggler;
应该是
set('toggler', !toggler);