43
42

More than 5 years have passed since last update.

いまの時代、JavaScript側でQRコードを生成できるんですね

Last updated at Posted at 2014-08-21

ということで、試してみた。手を抜くために、angular-qr というのを使いました。

結果(デモ)

導入手順

前提

手順(AngularJSの雛型の生成後)

  • Bower で angular-qr をインストール

    $ bower install angular-qr --save
    
  • $ grunt bower-install とするか、もしくは index.html に下記を追記します。

    app/index.html
    <script src="bower_components/qrcode/lib/qrcode.js"></script>
    <script src="bower_components/angular-qr/src/angular-qr.js"></script>
    
  • AngularJS に組み込み

    app/scripts/app.js
    'use strict';
    
    angular.module('qrTestApp', [
      'ngCookies',
      'ngResource',
      'ngSanitize',
      'ngRoute',
    +  'ja.qr'
    ])
  • この状態で使えるようになっているはずなので、後は Controller と View を書きます。

    app/scripts/controllers/main.js
    'use strict';
    
    angular.module('qrTestApp')
      .controller('MainCtrl', ['$scope', function ($scope) {
    
        $scope.string = '';
    
      }]);
    
    app/views/main.html
    <div ng-controller="MainCtrl">
        <div class="header">
          <h3 class="text-muted">QRコードのテスト</h3>
        </div>
        <p>
            <input type="text" placeholder="http:// ※日本語はNG" size="30" ng-model="string">
        </p>
        <br>
        <p>
            <qr text="string" size="150"></qr>
        </p>
    </div>
    
  • 以上!

ほか

43
42
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
42