Skip to content

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

Open
@semlinker

Description

@semlinker

一、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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions