PragmaticClub / ng2-qrcode

Angular2 QRCode generator based on qrcodejs
MIT License
16 stars 11 forks source link

import QRCode with typescript import #1

Closed yahyaKacem closed 5 years ago

yahyaKacem commented 8 years ago

Instead of a script tag in the index.html it's better to import this in the ng2-qrcode.ts file like this:

import 'qrcode';
declare let QRCode: any;

with this in system-config.ts:


var  map = {
    'app':                        'src', // 'dist',
    'rxjs':                       'https://npmcdn.com/rxjs@5.0.0-beta.6',
    'qrcode':                     'https://rawgit.com/davidshimjs/qrcodejs/master',
    'angular2-in-memory-web-api': 'https://npmcdn.com/angular2-in-memory-web-api', // get latest
  };

  //packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'app':                        { main: 'app.ts',  defaultExtension: 'ts' },
    'rxjs':                       { defaultExtension: 'js' },
    'angular2-in-memory-web-api': { defaultExtension: 'js' },
    'qrcode':                     { main: 'qrcode', defaultExtension: 'js' }
  };

here's a plunker with an example;

adamduren commented 8 years ago

@yahyaKacem this should be addressed as in PR #4. If you're using the latest webpack builder in angular-cli it should just work however if still on systemjs. You'll need the above except instead of qrcode I think it should be qrcodejs2.