这是我第一次使用 Angular、Edge.js 或调用 API。我不确定我是否做对了,但我肯定做错了什么,因为它不起作用。
为了从用 C# 编写的 API 获取数据,我在 Angular 项目的服务中使用 Edge.js。
数据服务.ts:
import { Injectable, ValueProvider } from '@angular/core';
import * as edge from "edge";
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor() { }
getData(type: string, method: string) {
let data = edge.func({
assemblyFile: 'C:\Program Files\Common Files\Siemens\Automation\Simatic OAM\bin\CC.CommonInterfaces.dll',
typeName: `CC.CommonInterfaces.${type}`,
methodName: `${method}`
});
return data(null, function(error, result) {
if (error) throw error;
console.log(result);
return result;
});
}
}
然后我只是在这样的组件中使用正确的参数调用 getData 方法:
onClickTestAPI() {
this.dataSrv.getData("IState", "IsTunnelActive");
}
但是在运行 Web 服务器时,控制台输出显示如下:
core.js:4002 ERROR Error: Uncaught (in promise): Error: Unexpected token '<'
Evaluating https://localhost:8888/edge
Loading ccui/ccui.umd.js
SyntaxError: Unexpected token '<'
at eval (<anonymous>)
at Qe (system.js:4)
at system.js:4
at T (system.js:4)
at T.h (system.js:4)
at T (system.js:4)
at system.js:4
at system.js:4
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
at Object.onInvoke (core.js:26255)
at resolvePromise (zone.js:852)
at zone.js:762
at rejected (tslib.es6.js:69)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
at Object.onInvoke (core.js:26255)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:390)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
at zone.js:910
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:26246)
甚至没有 API 响应(或者至少我找不到它)。
知道我哪里出错了吗?