如何使用深度相等(Angular 7) [英] How to use deep-equal (Angular 7)
问题描述
通过VS代码自动导入:
Auto import by VS Code:
import deepEqual = require('deep-equal');
不起作用:
错误TS1202:定位时无法使用导入分配ECMAScript模块.考虑使用"import * as"来自"mod"的ns",'从"mod"导入'{a}','从'mod'导入d或其他模块格式代替.
error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
然后我尝试这样做:
import * as deepEqual from 'deep-equal';
错误TS2497:模块'"path/@ types/deep-equal/index"'解析为非模块实体,无法使用此构造导入.
error TS2497: Module '"path/@types/deep-equal/index"' resolves to a non-module entity and cannot be imported using this construct.
像这样:
import {deepEqual} from 'deep-equal';
错误TS2305:模块'"C:/Projects/ManagerServer/Src-LoyaltyCoin.ManagerServer.Core/ManagerWeb/ClientApp/node_modules/@types/deep-equal/index"'没有导出的成员'deepEqual'.
error TS2305: Module '"C:/Projects/ManagerServer/Src-LoyaltyCoin.ManagerServer.Core/ManagerWeb/ClientApp/node_modules/@types/deep-equal/index"' has no exported member 'deepEqual'.
我不知道该如何导入.如果对此没有解决方案,请建议我使用另一个库来比较Angular 7的对象.
I haven't got ideas how can I import this. If there's no solution for this, please suggest me another library to compare objects for Angular 7.
推荐答案
将脚本添加到您的 angular.json
文件中:
Add the script to your angular.json
file :
scripts: [
"node_modules/deep_import/name.of.minified.file.js"
]
并在您的组件中声明一个变量:
And declare a variable in your component :
import { Component } from '@angular/core';
....
declare const deepEqual: any;
Or, you can find typings for it and install them, and import it like any other dependency :
import * as deepEqual from 'deep-equal';
编辑只是语法问题.我建议您打开存储库,然后参见语法.正确的是
EDIT Just a syntax issue. I suggest you open the repository and see the syntax. The correct one is
import deepEqual from 'deep-equal';
您可以在此 stackbltiz
这篇关于如何使用深度相等(Angular 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!