试图让dom-if工作

时间:2016-01-07 03:51:49

标签: dart polymer-1.0 dart-polymer

我正在尝试使用纸张切换按钮删除并添加模板内容。但是,即使切换正在进行,我也无法看到模板的内容。

使用的代码如下所示:

.dart

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元素的内容永远不可见。它似乎没有被调用?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

toggler = !toggler;

应该是

set('toggler', !toggler);