Show a JS script component in Ember/handlebars app [duplicate]

牧云@^-^@ 提交于 2019-12-11 17:14:28

问题


I need to embed a Javscript component (e.g. a Stripe pay button https://stripe.com/docs/checkout ) in my ember app, but apparently I can’t simply put a script tag inside the handlebar script tag.. any suggestion on how this can be done please?


回答1:


Create a view and add the script in the didInsertElement hook.
Here is a working demo.

App.StripeView = Em.View.extend({
  didInsertElement: function() {
    var stripeScript = 
      '<script src="https://checkout.stripe.com/checkout.js" '+
        'class="stripe-button" data-key="pk_test_6pRNASCoBOKtIshFeQd4XMUh" '+
        'data-image="/square-image.png" '+
        'data-name="Demo Site" '+
        'data-description="2 widgets ($20.00)" '+
        'data-amount="2000">'+
      '</script>';

    this.$().append(stripeScript);
  }
});

And use it in your template like

{{view App.StripeView}}


来源:https://stackoverflow.com/questions/24751621/show-a-js-script-component-in-ember-handlebars-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!