var appModule = angular.module('app', []);
appModule.directive('qrcode', function() {
    return {
        restrict: "A",
        scope: {
          text    : '=',
          options : '='
        },
        link: function(scope, elem, attrs) {
          var $elem, options;
          $elem = $(elem);
          options = { //获取元素的宽度和高度
            width: $elem.width(),
            height: $elem.height()
          };
          angular.extend(options, scope.options);
          scope.$watch('text', function(newText) {
            if (newText) {
              options.text = newText;
              $(elem).qrcode(options);//重新生成二维码
            }
          });
        };
    };
});
下载的方法在angular中可以封装成一个service使用。
小伙伴们会使用qrcode生成二维码了吧,确实很好用,希望大家能够喜欢。
您可能感兴趣的文章:
