0
votes

In principal HTML page: index.html

<poly-container a="Hi">
    <poly-item b="hi"></poly-item>
</poly-container> 

In Polymer HTML definition: polycontainer.html

<poly-container>
    <template> ...
        <content></content>
    </template> 
</poly-container>

In Dart class: polycontainer.dart ...Have tag <content> for render external DOM; ...and the 2 classes: PolyContainer and PolyItem

  processList() // calling from PolyContainer Constructor;
  {
      PolyItem cl;  
      HtmlElement a;

      ContentElement cont=shadowRoot.querySelector('content');
      List<Node> chil=cont.getDistributedNodes();

      for (var i=0; i < chil.length; i++) {  
         if ( chil[i].nodeName == 'POLY-ITEM' ) {   
           a=chil[i];  // (1)  
           cl=chil[i] as PolyItem; // (2)
           cl=a as PolyItem; // (3)
         }
         chil[i].remove();
      }
  }

(1) Cast OK; (chil[i] is type Node and "a" is type HtmlElement (Node->Element->HtmlElement)

(2)* Exception: type 'HtmlElement' is not a subtype of type 'PolyItem' in type cast.

(3)* Exception: type 'HtmlElement' is not a subtype of type 'PolyItem' in type cast.

Option 2 and 3 tested at different times.

I thought if we need to start some variable or call a function in the PolyItem constructor. Someone tried to cast an extended class PolymerElement?

1

1 Answers

0
votes

This should work.

Just set a breakpoint and run your app. The debugger stops at the breakpoint and shows you information like type and value or the variables in scope.
You can also add print(chil[i]); which usually gives information about the type (if you don't use DartEditor or the debugger doesn't work which still happens sometimes).

You should post the entire code of you PolyContainer element HTML and Dart.
If it contains code that doesn't have anything to do with the problem create a minimal example that allows to reproduce the problem and post this code.