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

Problem with params #48

Closed
brunocascio opened this issue Jun 4, 2015 · 2 comments
Closed

Problem with params #48

brunocascio opened this issue Jun 4, 2015 · 2 comments

Comments

@brunocascio
Copy link

Hi!

How to pass params from properties?
In this case, movieId:

Polymer({
      is: "yts-movie",
      movieId: 15,
      ready: function() {
        console.log('ready yts-movie')
      },
      ytsMovieResponse: function(event, result){
          console.log(result.response)
      }
});
<iron-ajax
        auto
        url="https://yts.to/api/v2/movie_details.json"
        params='{"movie_id": "{{ movieId }}" }'
        handle-as="json"
        on-response="ytsMovieResponse"
        debounce-duration="0">
</iron-ajax>

request HTTP is

https://yts.to/api/v2/movie_details.json?0=%7B&1=%22&2=m&3=o&4=v&5=i&6=e&7=_&8=i&9=d&10=%22&11=%3A

@cdata
Copy link
Contributor

cdata commented Jun 4, 2015

You need to specify movieId as a property of the yts-movie element. Please refer to https://github.com/Polymer/polymer/blob/master/PRIMER.md#property-binding for more information on binding properties.

ALSO, you cannot do binding in the middle of an attribute value the way you did for params. You must bind the whole attribute value, not just part of it. You can use an annotated computed property to do what you want.

Below is a fixed-up version of your example:

Polymer({
      is: "yts-movie",
      properties: {
        movieId: {
          type: Number,
          value: 15
        }
      }
      ready: function() {
        console.log('ready yts-movie')
      },
      paramsForMovieId: function(movieId) {
        return { movie_id: movieId };
      },
      ytsMovieResponse: function(event, result){
          console.log(result.response)
      }
});
<iron-ajax
        auto
        url="https://yts.to/api/v2/movie_details.json"
        params="{{paramsForMovieId(movieId)}}"
        handle-as="json"
        on-response="ytsMovieResponse"
        debounce-duration="0">
</iron-ajax>

Please refer to https://github.com/Polymer/polymer/blob/master/PRIMER.md#annotated-computed-properties for more information on annotated computed properties.

@cdata cdata closed this as completed Jun 4, 2015
@brunocascio
Copy link
Author

Great! Thanks!

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

2 participants