【发布时间】:2018-01-27 22:57:51
【问题描述】:
WebStorm 告诉我它无法解析文件“base-64”,这是我最近通过 npm install 安装的一个节点模块。但是,我的应用程序没有出现错误,我可以毫无问题地使用 base64 变量。
我需要改变什么来消除错误?
- Angular/cli 1.1.3
- webpack 2.4.0
【问题讨论】:
标签: angular typescript webpack webstorm angular-cli
WebStorm 告诉我它无法解析文件“base-64”,这是我最近通过 npm install 安装的一个节点模块。但是,我的应用程序没有出现错误,我可以毫无问题地使用 base64 变量。
我需要改变什么来消除错误?
【问题讨论】:
标签: angular typescript webpack webstorm angular-cli
当你想通过 angular-cli 使用第三方脚本时,你需要:
安装de包: npm install base-64
在 .angular-cli.json 脚本中导入包:
...,
"scripts": [
"../node_modules/base-64/base64.js"
],
...
/**
* The module that includes all the basic Angular directives like {@link NgIf}, {@link NgForOf}, ...
*
* @stable
*/
export declare class CommonModule {
}
在这种情况下,对于 base64,您没有模块,那么您可以使用:
import { Component, OnInit } from '@angular/core';
declare let base64: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'app';
ngOnInit() {
console.log(base64);
}
}
【讨论】: