代码之家  ›  专栏  ›  技术社区  ›  Mohamed Adel

带角6的CamanJs

  •  1
  • Mohamed Adel  · 技术社区  · 8 年前

    我试着用角6的相机。如何添加js lib并在npm上没有类型时与angular一起使用。我遵循许多步骤

    • 将其添加到角度.json作为脚本使用其在节点模块中的路径

    • 将其导入组件,如

      ngAfterViewInit() {
           Caman('#image-id', function () {
                this.brightness(10);
                this.contrast(20);
              });
         }
    

    但当启动服务器时,我得到了这个错误

    enter image description here

    链接到代码: https://stackblitz.com/edit/angular-d5g941

    2 回复  |  直到 8 年前
        1
  •  1
  •   SiddAjmera    8 年前

    内部 .angular-cli.json 的 scripts caman

    "scripts": [
        "../node_modules/path-to-caman"
    ],
    

    如果角度为6英寸 angular.json 的 数组,将路径添加到 卡曼

    "scripts": [
        "node_modules/path-to-caman"
    ],
    

    Caman 这样地:

    declare var Caman: any;
    

    你呢 不要 需要做什么

    import * as Caman from 'path-to-caman'
    

    只是将脚本添加到中的脚本数组 .angular-cli / 角度.json (在Angular 6的情况下)将它添加到全局范围,并且您可以从您的组件访问它。

    ngAfterViewInit 生命周期钩子方法,因为它试图通过id访问DOM元素。

        2
  •  0
  •   Mohamed Adel    8 年前
    推荐文章