-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.0] polymer attribute used in a string behaving differently from 0.5 #1770
Comments
There are several issues with your code, all easily fixable, though. First, bindings in Polymer 1.0 work differently now and are more explicit. When you bind to a property using <my-element prop="{{variable}}">...</my-element> You aren't binding to the When you want to bind to an element's attribute instead of a property, as is the case with binding to attributes on native elements, which don't have the abstractions that custom elements do, you must use the <a href$="{{variable}}">...</a> Second of all, Polymer now resolves The third implicating factor is that Polymer 1.0 no longer supports string concatenation with bindings, meaning that a binding must take up the entirety of the attribute/property or element's content that it is bound to. Basically, you can't do this anymore: <a href="/mysite/hello{{myAttrib}}">...</a> You'd have to do this: <a href="{{myAttrib}}">...</a> If you need to concatenate strings for bindings, you can achieve this effect with computed properties. Computed properties are functions in your element prototype which generate a value based on other properties in your element. Here's a complete (though untested) example based on your code: <dom-module id="my-element">
<template>
<a href$="{{_getHref(myAttrib)}}">...</a>
</template>
</dom-module>
<script>
Polymer({
is: 'my-element',
properties: {
myAttrib: {
type: String,
reflectToAttribute: true
}
},
_getHref: function(myAttrib) {
return '/mysite/hello' + myAttrib;
}
});
</script> |
great it worked thanks for the education. |
@vsimonian My element is not clickable, my code is exactly same with your instance. And I don't get any error in console. <bindable-link myAttrib="{{variable}}">..</bindable-link> |
Thats better it works now: <bindable-link my-attrib="{{variable}}">..</bindable-link> |
In 0.5 I created my own element and gave it an attribute that was later used in an href as below - It worked in 0.5 but get blank for attribute in 1.0 when it is put in a string with quotes works separately so know its being passed. Not sure if this is a bug or was I doing it wrong in the first place.
Following worked in 0.5
Following fails in 1.0
The text was updated successfully, but these errors were encountered: