-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
"on" attribute on amp-list and amp-list specific events #9862
Comments
/to @choumx |
Thanks for the filling this issue. For your use case, try using an <amp-state id="myState" src="<my-url>"></amp-state>
<amp-list [state]="myState"></amp-list> The latter is a relatively new feature -- we'll add documentation for it soon. /cc @ericlindley-g |
This is awesome William. Thanks. |
Wouldn't this would only update the amp-list with the loaded state if AMP.setState() is called again somewhere else? I tried it out, and I couldn't get the amp-list to load unless I manually triggered a button that had on="tap:AMP.setState()". Is there a way to render the specified bindings automatically after the JSON loads? |
@alexlyeh Correct! Though this is slightly different from the original FR. The concern with automatically triggering mutation after the XHR completes is that it could cause dramatic, unexpected changes to the document (e.g. page jumping) so we try to restrict that to direct user interaction. One way to accomplish this now that we have trustful actions (#9824) is to add a new low-trust event <amp-state id="myState" src="<my-url>" on="fetch:myList.update"></amp-state>
<amp-list id="myList" [state]="myState"></amp-list> Another way to do this is to delay render of <!-- Detect if template has bindings.
If so, wait for bind eval before update (w/ timeout). -->
<amp-list id="myList" src="<my-url>">
<template type="amp-mustache">
<p [text]="foo.bar"></p>
</template>
</amp-list> Note that the latter won't update the local bindable state with the XHR response. @ericlindley-g This is similar to @cramforce's |
@choumx Thanks for the clarifications! |
@choumx in you example src attribute is dropped from amp-list. How would one get away with not specifying the src attribute on amp-list? Is not src a required attribute? |
@hamousavi Currently it is required -- my example is hypothetical. Is your use case the same as above? |
@choumx — this is interesting. Since developers could specify their own placeholder/loading indicator, this might fit the need nicely. |
Agreed with @ericlindley-g . This will nicely fit our case. |
@aadi1295 FYI you can also ask AMP questions on the amphtml-discuss group or on our Slack channel. |
I'm getting this in the console when using [state]
is this still the recommended way to update the list dynamically? I've tried using [src] pointing to the name of the object in the state, but it complains:
|
@leoshaw Yes, please use |
I'd like to use this in order to compute a dynamic height, based on the amount of items loaded for the amp-list. But it seems that the solution pointed out here is not yet implemented? |
|
How to solve this with load-more="auto" attribute set? |
What's the issue?
AMP provides a number of element specific events as listed on https://github.com/ampproject/amphtml/blob/master/spec/amp-actions-and-events.md#element-specific-events
Can we have an amp-list specific event that is triggered when the amp-list fetching is completed?
How do we reproduce the issue?
We are looking for something like the "load" event as outlined in the following example
<amp-list on=”load:AMP.setState({some state : json response})” … >
So that we can store the response in an AMP state.
The text was updated successfully, but these errors were encountered: