dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
181 stars 33 forks source link

null object when using $ selector of node inside dom-if #667

Closed terrywarwar closed 8 years ago

terrywarwar commented 8 years ago

$['id1'] returns null when inside dom-if template. Works fine when it's outside the dom-if.

<template is="dom-if" if="{{!isLogin}}">
   <div id="id1"></div>
</template>
zoechi commented 8 years ago

That's "as designed". If you wrap your code with asnyc(...) to give Polymer time to stamp the template, it will work.

terrywarwar commented 8 years ago

Tried async(()=>($['md'] as PaperDrawerPanel).togglePanel()); and still getting a null object.

zoechi commented 8 years ago

Also when isLogin is false?

terrywarwar commented 8 years ago

It's set on ready() set("isLogin", false);

jakemac53 commented 8 years ago

I am pretty sure this is working as intended. The $ map is only going to contain things that exist on initial render. You could try setting isLogin to false in its initializer but I am not sure if that would work either. You should be able to use $$('#md') instead which does an actual query for the element.

See https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#node-finding