Skip to content
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

[0.9] if="{{ 1 < 2 }}" not supporded?! #1499

Closed
teckays opened this issue May 7, 2015 · 8 comments
Closed

[0.9] if="{{ 1 < 2 }}" not supporded?! #1499

teckays opened this issue May 7, 2015 · 8 comments

Comments

@teckays
Copy link

teckays commented May 7, 2015

This si not working!

<template is="dom-repeat" items="{{items}}">
    <template is="dom-if" if="{{index == 2}}">
      <!-- show third item -->
    </template>
</template>

a bug or a feature?

@teckays
Copy link
Author

teckays commented May 7, 2015

@arthurevans
Copy link

Feature. No expressions are supported in bindings, except for ! and inline functions.

https://www.polymer-project.org/0.8/docs/migration.html#data-binding

In general, expressions like this can be replaced with inline functions or computed properties, like this:

<template is="dom-if" if="isIncluded(index)">

However, it appears that inline functions can't be defined on an auto-binding template. Not sure whether that's a bug or not.

@arthurevans
Copy link

Opened #1500 for autobinding template issue. Closing this because it's working as intended.

@chuckh
Copy link
Contributor

chuckh commented May 7, 2015

@arthurevans I think you mean this:

 <template is="dom-if" if="{{isIncluded(index)}}">

I have a working example at http://plnkr.co/edit/7KKqwIVVKVXt44nkuBgi?p=preview using this syntax with a custom element. It does not work using auto-bind

@arthurevans
Copy link

Yep, I was writing too fast there. Thanks, Chuck.

@teckays
Copy link
Author

teckays commented May 8, 2015

Ok, thanks for pointing out!

@kevinpschaaf
Copy link
Member

@teckays Also note, the case you showed is a good candidate for using the filter feature of dom-repeat. It doesn't support filtering based on index (so if that's really your use case maybe not), but if your item has the criteria you would use to switch the dom-if, you'd be better using filter than dom-if, since you'd be stamping less stuff.

http://jsbin.com/dogizasicu/1/edit?html,console,output

@teckays
Copy link
Author

teckays commented May 9, 2015

@kevinpschaaf didn't know about the filter attribute, thank you for sharing, will definitely use it when appropriate. The use case I have requires stamping all items but some of them treat in a different way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants