I'm attempting to retrieve a list of customers by calling a GET API from a dashboard constructor as shown below:
// tslint:disable-next-line:max-line-length
constructor(public addCustomerDialog: MatDialog, private router: Router, private route: ActivatedRoute, private customerService: CustomerService) {
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/login';
this.customerList = getCustomers();
}
getCustomers() {
const jwt = localStorage.getItem('jwt');
// making an AJAX call
this.customerService.getCustomers(jwt).subscribe((res) => {
console.log(res);
}, (err) => {
alert('Token expired. Need to login again!');
this.router.navigateByUrl(this.returnUrl);
console.log(err);
});
}
An error I encounter is:
ERROR in error TS5055: Cannot write file '/home/spartan/Documents/development/ktf-standalone/api/config/main.js' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
error TS5055: Cannot write file '/home/spartan/Documents/development/ktf-standalone/api/controllers/controllerCustomer.js' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
error TS5055: Cannot write file '/home/spartan/Documents/development/ktf-standalone/api/models/customer.js' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
I have a tsconfig.json file in the root directory.
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"allowJs": true
}
}
By commenting out a few lines in the constructor, I am able to start my server.
Is calling the API in the constructor the correct approach? Am I overlooking something here?
Project structure: https://i.sstatic.net/lDPZ3.png