0

I am trying to pass an object reference to the Dart script associated with a Polymer element. I have found the element in the DOM but I can't figure out how to call a method in the Dart associated with the element or any other way to dynamically pass an object to the Polymer element to be displayed.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
user3329151
  • 145
  • 1
  • 1
  • 5

1 Answers1

0

Basically you just get a reference by using for example querySelector('#someid') and just assign the value to a field or setter or call a method and pass it as an argument.

querySelector('#someid').someField = someValue;
querySelector('#someid').setValue(someValue);

This might produce a hint in DartEditor but should still work when the code is executed. To get rid of the hint you can "cast" like

(querySelector('#someid') as MyComponent).someField = someValue;
querySelector('#someid') as MyComponent).setValue(someValue);

You need to import MyComponent to make this work.

If this doesn't something with your code might be wrong. For example the main() method if you have one. See how to implement a main function in polymer apps for more details.

If nothing of the above works, please add code to your question that shows what you're trying to accomplish.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • That worked well but I did need to use shadowRoot.querySelector, I am not sure why. – user3329151 Dec 12 '14 at 23:02
  • I didn't add it because you wrote that selecting the element is already working. Without `shadowRoot.` `querySelector` searches the children of the element (the content) not the elements in the elements template (shadow DOM). – Günter Zöchbauer Dec 13 '14 at 08:40