如何在 angular 2+ 中使用功能齐全的 JsonPath?

How to use fully functioning JsonPath in angular 2+?

我关注了https://www.npmjs.com/package/jsonpath。尝试了一种包含外部 js 文件的方法,但没有成功。

导入 jsonPath 在 -

之后起作用
import * as jsonPath from 'jsonpath/jsonpath';

JsonPath plush 也有效 JSONPath-plus,与 Jsonpath 相同。我有以下适合我的代码片段-

安装JSONPath-plus

npm install jsonpath-plus

angular.json 文件

"scripts": [
    "node_modules/jsonpath-plus/dist/index-umd.js",
    "src/assets/js/jsonpath.js"
]

jsonpath.js 有以下代码 -

function jsonPath() {
  return JSONPath;
}

现在在 ts 文件中使用这个函数,声明如下 -

declare const jsonPath: any;
// use it like
 jsonPath().JSONPath(path, json);