我正在尝试使用角为6的凸轮。如何添加js并在npm上没有任何类型的情况下使用它。我走了很多步
导入*作为Caman从“节点模块中的路径到caman”
ngAfterViewInit() { Caman('#image-id',函数() { this.brightness(10);this.contrast(20);});}
但是当启动服务器时,我会得到这个错误。

发布于 2018-09-09 09:07:29
发布于 2018-09-10 08:08:34
在.angular-cli.json的scripts数组中,将路径添加到caman
"scripts": [
"../node_modules/path-to-caman"
],在angular.json的scripts阵列中角为6的情况下,向caman添加路径。
"scripts": [
"node_modules/path-to-caman"
],然后,在组件中声明一个名为Caman的变量,如下所示:
declare var Caman: any;你不需要去做
import * as Caman from 'path-to-caman'因为您的编译器将抛出一个错误,说明:
找不到模块“caman”。
只需将脚本添加到.angular-cli/angular.json中的脚本数组(在角度为6的情况下),就会将脚本添加到全局范围,您将能够从组件中访问它。
此外,在ngAfterViewInit生命周期钩子方法尝试通过id访问DOM元素时,请确保调用它上的任何函数。
https://stackoverflow.com/questions/52206640
复制相似问题