1

I have a polymer element

 import 'package:polymer/polymer.dart';

 @CustomTag('custom-project-button')
 class ProjectButton extends PolymerElement {
   @observable String project = "none";
   @observable String path = "none";

   ProjectButton.created() : super.created();
 }

the polymer html

 <!DOCTYPE html>
 <polymer-element name="custom-project-button">
   <template>
     <link rel="stylesheet" href="projectButton.css">

     <template>
       <div class="custom-project-button">
       <div class="box"></div>
         <h1>Project: {{project}}:</h1>
         <h2>Path: {{path}}:</h2>
       </div>  
     </template>

   <script type="application/dart" src="projectButton.dart"></script>

and inside Main of my projct I call

 import 'package:polymer/polymer.dart';
 import 'dart:html';
 import 'dart:convert' show JSON;
 import 'package:params/client.dart';

 DivElement content = querySelector("#content");

 void main() {
   querySelector("#warning").remove();
   initPolymer().run(() {
     initParams();
     print("Request List");
     var url = "http://127.0.0.1:8099/init";
     var request = HttpRequest.getString(url).then(displayProjects);
   });
 }

 void displayProjects(responseText) {
   Map userProjects = JSON.decode(responseText);

   userProjects.forEach((k,v){
     Element polyItem = new Element.tag("custom-project-button");
     polyItem.project = k.toString();
     polyItem.path = v.toString();
     content.append(polyItem);
   });

 }

then I get

 Uncaught Error: Class 'HtmlElement' has no instance setter 'project='.

but for some reason it worked a few days ago in another project, now it also stoped working there

tried to set a constructor in polymer to be able to say new projectButton() but wont work either

H.R.
  • 496
  • 4
  • 14
  • Have you tried `Polymer.onReady()`? – Günter Zöchbauer Jun 04 '14 at 13:37
  • not yet, will do when I am home ;) :) cant wait to test it. – H.R. Jun 04 '14 at 16:12
  • I was missing a closing in my poly html .. dart editor didnt tell me – H.R. Jun 05 '14 at 02:32
  • hmm I dont really know what the problem was, but its gone.. one part was the one missing closing template in my poly html, but I didnt change anything else in respect of the dart file so I dont know why the *'HtmlElement' has no instance setter 'project='* doesnt turn up again, (well I updated the editor and deleted all packages lock files and reinstalled them.. wired.. – H.R. Jun 05 '14 at 13:06
  • 1
    If this was a runtime error/exception it was caused by the invalid Element definition (missing closing template tag). It has to be a `ProjectButton` even when the variable type is just `HtmlElement` to have the `project` setter. When the upgrade-process (make a custom element from a unknown HTML tag) failes it doesn't become a `ProjectButton` thus has no `project` setter. When it was just a warning in DartEditor it might have been a bug in the analyzer which might have been fixed in the meantime. – Günter Zöchbauer Jun 05 '14 at 13:24

1 Answers1

0

I think you just need a cast to get rid of the warning

ProjectButton polyItem = new Element.tag("custom-project-button") as ProjectButton;
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Exception: type 'HtmlElement' is not a subtype of type 'ProjectButton' in type cast. its wired in 1.4.2 dartabaseTutorials post example is working fine. and there I use Element e = Element.tag .. e.xyz = 13 – H.R. Jun 02 '14 at 20:43
  • Do you use Polymer 0.10.0? I didn't experience such problems yet with 1.5.0-x. Usually this message indicates that the custom element isn't upgraded. Do you import the elements HTML somewhere? ``. How do your Polymer import and script tags look in your entry page? – Günter Zöchbauer Jun 03 '14 at 05:47
  • Maybe it's a timing issue. You could try to embed your code in `Polymer.onReady.then` like shown here http://stackoverflow.com/questions/20932180 – Günter Zöchbauer Jun 03 '14 at 05:57
  • I'm an polymer 0.9.5+2 – H.R. Jun 04 '14 at 16:15