问题描述
我关注了https://www.npmjs.com/package/jsonpath。尝试了一种包含外部js文件的方法,但是没有运气。
解决方法
导入jsonPath在-
之后起作用import * as jsonPath from 'jsonpath/jsonpath';
JsonPath长毛绒也可以使用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);