Inside .angular-cli.json
's scripts
array, add the path to caman
"scripts": [
"../node_modules/path-to-caman"
],
In case of Angular 6 in angular.json
's scripts
array, add the path to caman
"scripts": [
"node_modules/path-to-caman"
],
and then, inside your Component, just declare a variable named Caman
like this:
declare var Caman: any;
You don't need to do
import * as Caman from 'path-to-caman'
as your compiler will throw an error stating that:
Cannot find module 'caman'.
Just adding the script to the scripts array in .angular-cli
/angular.json
(in case of Angular 6) will add it to the global scope and you'll be able to access it from your components.
Also, make sure that you call any function on it inside the ngAfterViewInit
lifecycle hook method as it tries to access the DOM elements by id.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…