angular - 如何使用深度相等(Angular 7)

标签 angular typescript npm compare

通过 VS 代码自动导入:

import deepEqual = require('deep-equal');

不起作用:

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';

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';

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 的对象。

最佳答案

将脚本添加到您的 angular.json 文件中:

scripts: [
  "node_modules/deep_import/name.of.minified.file.js"
]

然后在你的组件中声明一个变量:

import { Component } from '@angular/core';
....
declare const deepEqual: any;

或者,您可以找到 typings为此并安装它们,并像任何其他依赖项一样导入它:

import * as deepEqual from 'deep-equal';

编辑 只是语法问题。我建议你open the repository并查看语法。正确的是

import deepEqual from 'deep-equal';

正如您在此 stackbltiz 中看到的那样

关于angular - 如何使用深度相等(Angular 7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53632149/

相关文章:

javascript - Ionic 2 - 访问 Controller 中的 ngModel

typescript - Angular 2、Visual Studio 2015 更新 1、类型脚本配置

javascript - TypeScript - 动态定义实例时不能严格限制类型

angular - 在Angular中按对象属性对元素进行分组

node.js - 服务器无法识别 Socket.io 语法

node.js - npm 未在项目目录中创建 node_modules 文件夹

javascript - 如何仅在鼠标滚轮滚动时触发

angular - 在 Angular 2 中手动注入(inject) Http

javascript - nodejs导入需要转换

typescript - Angular2 使用值等价或引用相等检测变化?