angular2-ionic2 icon indicating copy to clipboard operation
angular2-ionic2 copied to clipboard

Ionic 2 中如何引入第三方脚本库

Open semlinker opened this issue 8 years ago • 0 comments

一、typings 中包含 Type Definitions 文件

1.使用 npm 安装依赖

npm install bcryptjs --save

2.添加 Type Definitions 文件阻止编译器错误

2.1 安装 typings

npm install -g typings

2.2 安装 bcryptjs dt 文件

typings install dt~bcryptjs --save --global

二、 typings 中不包含Type Definitions 文件

index.html 文件中引入对应的文件:

<script src="bcrypt.min.js"></script>

在使用的 ts 文件中声明变量:

declare var dcodeIO: any;

export class HomePage {
    public bcryptjs: any;
    public hash: string;
    
    constructor() {
       this.bcryptjs = dcodeIO.bcrypt;
       this.hash = this.bcryptjs.hashSync("nraboy", 8);
    }
}

semlinker avatar Mar 03 '17 15:03 semlinker