0

I'm making a web app: front-end in Angular and back-end in Rails. When the user comes to my web app, I am going to show the pop up on top left. When user clicks "copy the code" button, the promo code should be copied to their laptop or desktop.

Here is view for the modal(I'm not adding CSS since it is not important for this question):

<!-- The Modal -->
<div id="myModal" class="modal">
    <!-- Modal content -->
    <div class="modal-content" style="text-align:center">
        <div class="modal-header">
            <span class="close">X</span>
            <h2>Welcome Hunt users!</h2>
        </div>
        <div class="modal-body">
            <p>$50 off.</p>
        </div>
        <div>
            <button class="button button-form-success button--orange vertical-offset--teensy modal-button">Yes
            </button>
        </div>
    </div>
</div>

Javascript file

var promocode = "promocode"
function copyPromo () {
    // business logic to copy the promocode to user's computer
}

I am trying to figure out how to copy promocode variable to user's computer but I cannot figure it out. I would appreciate any advice!

JoHksi
  • 517
  • 1
  • 7
  • 26

1 Answers1

0

Since there are multiple OS dependent ways to fill clipboard, I suggest you to use some angular clipboard library, like http://ngmodules.org/modules/ng-clipboard

Marat
  • 617
  • 5
  • 12
  • Gotcha. Would there be other way of solving this issue through Angular? I am not super fan of adding a lot of module to my Angular app. So I am just wondering. – JoHksi Jun 20 '16 at 06:51
  • I faced same problem couple of months ago, but i had no other way for fully automatic putting stuff into clipboard without additional user interaction like selecting or ctrl+C, that works on different systems in different browsers. If you let your visitor manually copy your code, you can just present your promo code. – Marat Jun 20 '16 at 06:58