Recently, I started working with Typescript and Aurelia framework. Currently, I am facing an issue while trying to implement the @autoinject decorator in a VS2015 ASP.NET MVC 6 project.
Below is the code snippet I am using:
import {autoinject} from "aurelia-framework";
import {HttpClient} from "aurelia-http-client";
@autoinject()
export class App {
http: HttpClient;
constructor(httpClient: HttpClient) {
this.http = httpClient;
}
activate() {
this.http.get("/api/test/")...
}
}
Upon running this code, I encounter an error stating that 'this.http' is undefined.
I suspect that enabling TypeScript's emitDecoratorMetadata flag could resolve this issue, but I am unsure on how to do so.
I attempted adding a tsconfig.json file to the project and setting the flag in compiler options, however, it resulted in multiple errors (duplicate identifier). How can I address these errors? Is there something specific I need to include under "files"?
Additionally, here is my config.js file for reference:
System.config({
baseURL: "/",
defaultJSExtensions: true,
transpiler: "typescript",
paths: {
"npm:*": "jspm_packages/npm/*",
"github:*": "jspm_packages/github/*"
},
map: {
"aurelia-bootstrapper": "npm:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e584909780898c84c8878a8a919691978495958097a5d4cbd5cbd5c887809184cbd4">[email protected]</a>",
"aurelia-framework": "npm:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1574606770797c74387367747870627a677e55243b253b2538777061743b243b253b22">[email protected]</a>",
"aurelia-http-client": "npm:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee8f9b9c8b82878fc3869a9a9ec38d82878b809aaedfc0dec0dec38c8b9a8fc0df">[email protected]</a>",
"typescript": "npm:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84f0fdf4e1f7e7f6edf4f0c4b5aab3aab1">[email protected]</a>",
....
}
});