web component - Polymer hostAttributes Error -
i have been following along polymer 1.0 developer guide , stumbled when getting specific part hostattributes.
when take example code docs:
hostattributes: { string-attribute: 'value', boolean-attribute: true tabindex: 0 }
and add prototype, browser keeps throwing error:
uncaught syntaxerror: unexpected token -
on lines there dashes. strangely, when put quotes around string-attribute
, boolean-attribute
, renders fine.
is error on part or error in docs somehow?
in way example represented string-attribute
, string-attribute
refers string attribute should set on label of element declaration. also, may have noticed way declaring string-attribute
in example, javascript assumes string-attribute
variable, , variables can not declared "my-variable" declared "myvariable", strings together.
think that's reason why should declared follows:
hostattributes: { "my-var": 'value',// javascript assumes my-bar string my-var-two: 'value'// javascript assumes my-bar-two variable (this fail) tabindex: 0 }
i hope have understood me, english bad.
edit
if custom elements needs html attributes set on @ create-time, these may declared in hostattributes property on prototype, where keys attribute name , values values assigned. values should typically provided strings, html attributes can strings;
hostattributes: { string-attribute: 'value', //string-attribute key, should inside "" because javascript's keys doesn't accepts "-" boolean-attribute: true//will fail because not key tabindex: 0//this works because javascript correct key }
...however, the standard serialize method used convert values strings, true serialize empty attribute, , false result in no attribute set, , forth
as can realize, serialized string values, never mentioned keys serialized string well. mentioned before, english bad , understood that.
Comments
Post a Comment