加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何将qrcode-generator导入角度2 app?

发布时间:2020-12-17 17:06:55 所属栏目:安全 来源:网络整理
导读:我正在尝试在我的应用程序中使用 qrcode-generator,但我的设置没有成功,即使它在 plunker工作,在我的应用程序中我使用angular-cli和angular 2.rc-1. 重现步骤: ng new newAppNamecd newAppNameng serve 它起作用了. npm i qrcode-generator // (note this i
我正在尝试在我的应用程序中使用 qrcode-generator,但我的设置没有成功,即使它在 plunker工作,在我的应用程序中我使用angular-cli和angular 2.rc-1.
重现步骤:

ng new newAppName
cd newAppName
ng serve

它起作用了.

npm i qrcode-generator // (note this is missing the svg support).
ng serve // still work

然后更改2个文件中的配置.
角-CLI-build.js:

var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
  return new Angular2App(defaults,{
    vendorNpmFiles: [
      'systemjs/dist/system-polyfills.js','systemjs/dist/system.src.js','zone.js/dist/**/*.+(js|js.map)','es6-shim/es6-shim.js','reflect-metadata/**/*.+(js|js.map)','rxjs/**/*.+(js|js.map)','qrcode-generator/**/*.+(js|js.map)','@angular/**/*.+(js|js.map)'
    ]
  });
};

和system-config.ts:

/**********************************************************************************
 * User Configuration.
 *********************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
  'qrcode-generator': 'vendor/qrcode-generator'
};
const packages: any = {
  'vendor/qrcode-generator': {
    main: 'qrcode',defaultExtension: 'js'
  }
};
// ... the rest is the same

编辑new-app-name.component.ts并像这样导入qrcode-geenerator

// vscode underline the qrcode-generator string and complai about not finding it
import * as qrcode from 'qrcode-generator';

然后ng服务仍然运行错误与此消息:

/path/to/project/newAppName/tmp/broccoli_type_script_compiler-input_base_path-jscpZEq5.tmp/0/src/app/new-app-name.component.ts
(3,25): Cannot find module ‘qrcode-generator’.

我尝试通过将其添加到typings.json文件来安装它的输入:

"globalDependencies": {
    "qrcode-generator": "registry:dt/qrcode-generator#0.0.0+20160412152159"
  }

然后运行:

typings i

安装成功,但仍然是同样的错误.
angular-cli版本:

angular-cli: 1.0.0-beta.5
node: 6.2.0
os: linux x64

我错过了什么吗?
我还缺少其他配置吗?

解决方法

我终于能够导入这个了,感谢 @JavascriptMick从 angular-cli’s gitter我做了以下,首先使格式全局:

'vendor/qrcode-generator': {
    format: 'global',main: 'qrcode.js'
  }

然后在导入时这样做:

import 'qrcode-generator';
declare let qrcode;

希望这有帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读