Javascript 在Angular 2中使用普通js代码(Angular cli)

Javascript 在Angular 2中使用普通js代码(Angular cli),javascript,angular,angular2-directives,angular2-modules,Javascript,Angular,Angular2 Directives,Angular2 Modules,我试图在我的项目中实现,但我甚至找不到在我的项目中使用vanilla js导入的方法 到目前为止,我已经尝试使用它作为指令,就像您使用jQuery插件一样,使用@angular/core中的ElementRef、Input等 我已经将脚本直接从我为Vanilla Tilt JS安装的中的脚本下的.angular cli.json文件中包含 我考虑将其用作指令,因为它有自己的data tilt属性,如下所示: import { Directive, ElementRef, HostListener

我试图在我的项目中实现,但我甚至找不到在我的项目中使用vanilla js导入的方法

到目前为止,我已经尝试使用它作为指令,就像您使用jQuery插件一样,使用
@angular/core
中的
ElementRef
Input

我已经将脚本直接从我为Vanilla Tilt JS安装的中的
脚本下的
.angular cli.json
文件中包含

我考虑将其用作指令,因为它有自己的
data tilt
属性,如下所示:

import { Directive, ElementRef, HostListener, Input } from '@angular/core';

@Directive({
    selector: '[data-tilt]'
})
export class ParallaxDirective {
    constructor(private el: ElementRef) {

    }
}
但是我找不到一个方法来做到这一点,尽管我已经努力了。我是新来的

我的问题是:


是否可以在Angular 2中使用普通javasciprt插件,如果可能,如何实现Vanilla Tilt JS插件?您应该能够导入Vinilla Tilt并使用传递到构造函数中的元素引用

import { Directive, ElementRef, HostListener, Input } from '@angular/core';

const VanillaTilt = require('vanilla-tilt');

@Directive({
    selector: '[data-tilt]'
})
export class ParallaxDirective {
    constructor(private el: ElementRef) {
      VanillaTilt.init(el.nativeElement, {
        max: 25,
        speed: 400
      });
    }
}

选中此项此处唯一缺少的是引用DOM的
el.nativeElement