Skip to content
This repository has been 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

Closed
scott-coates opened this issue Oct 21, 2013 · 3 comments
Closed

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

scott-coates opened this issue Oct 21, 2013 · 3 comments

Comments

@scott-coates
Copy link

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
@aczekajski
Copy link

It's the same as #4524

@scott-coates
Copy link
Author

Shit, I swear I searched for this issue first - guess I chose different keywords.

Anyway, for the time being, I'm using a directive to inject the script tag in the link function and it is helping me get around this issue:

@petebacondarwin
Copy link
Contributor

Closing as a duplicate of #4524 but the analysis here @scoarescoare is useful thanks.

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

No branches or pull requests

3 participants