When executing my code, a typescript error appears that "require" is not a function, which is why I declared the function beforehand, but now typescript complains that "Modifiers cannot appear here.". Can someone help me?
import { Injectable, ValueProvider } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class DataService {
edge : any;
constructor() {
declare function require(name: string); // "Modifiers cannot appear here."
this.edge = require('edge');
}
getData(type: string, method: string) {
var data = this.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;
});
}
}
declarein.d.tsfiles.InjectableandValueProviderform@angular/core. Checkout Rahuls answer.