Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

script tag is not executed in 1.2.0-rc.2 when using jQuery #4555

@scott-coates

Description

@scott-coates

As noted in this SO post, jusing jQuery should execute a script tag within a partial/template.

I tried using Stripe's Embedded Checkout feature, where a script tag is required to use an embedded form from Stripe's server. Example:

<script
  src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
  data-key="pk_test_xxxxxxxxxxxxxxxxxxx"
  data-amount="2000"
  data-name="Demo Site"
  data-description="2 widgets ($20.00)"
  data-currency="usd"
  data-image="/128x128.png">
</script>

The script tag was executed not by jQuery.

Investigating the issue, I can see that jQuery will not execute the script tag because these conditions are not met:

// Evaluate executable scripts on first document insertion
for (i = 0; i < hasScripts; i++) {
  node = scripts[ i ];
  if (rscriptType.test(node.type || "") && !data_priv.access(node, "globalEval") && jQuery.contains(doc, node)) {
    if (node.src) {
      // Hope ajax is available...
      jQuery._evalUrl(node.src);
    } else {
      jQuery.globalEval(node.textContent.replace(rcleanScript, ""));
    }
  }
}

The problem is that this condition evaluates to false:
jQuery.contains(doc, node)

I believe this issue was introduced when animations were created because the document doesn't actually contain the template from ng-include until after $animate.enter(currentElement, null, $element); is called.

currentElement.html(response);
//By this time, jQuery has already tried to evaluate the script and decided NOT to because the document doesn't actually contain the element yet
$animate.enter(currentElement, null, $element);
//Now the document contains the element in the DOM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions