我正在尝试在我的应用程序中使用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个文件中更改配置。angular-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 serve
这条消息仍在运行错误:
/path/to/project/newAppName/tmp/broccoli_type_script_compiler-input_base_path-jscpZEq5.tmp/0/src/app/new-app-name.component.ts(3,25):找不到模块“ qrcode-generator”。
我尝试通过将其添加到Types.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从角CLI的小胶质我做了如下,首先进行格式的全局:
'vendor/qrcode-generator': {
format: 'global',
main: 'qrcode.js'
}
然后在导入时以这种方式进行:
import 'qrcode-generator';
declare let qrcode;
希望对您有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句