Using amp-bind for many unique amp-img src'es using setState

67 Views Asked by At

I am using amp-bind with setState to update the amp-img URLs for different swatches at https://beta.webfast.co/magma/collections-galaxy.html

However, even though I am updating specific variables such as s0, there are other divs that are getting updated which isn't the intent.

  1. Visit https://beta.webfast.co/magma/collections-galaxy.html
  2. Scroll to product that has title "Last Resort Men's Tee" (the div on the left)
  3. Click on the first swatch that has the color white.
  4. The product image div to the right of the swatch disappears.
  5. The neighboring div image should not be affected.
1

There are 1 best solutions below

0
anurag On

Turns out, setState needs to have a default value, adding:

<amp-img [src]="s0 || 'my_default_url'"></amp-img>

helped fix the issue.

Reference: https://github.com/ampproject/amphtml/issues/28857