I have an Angular application that shows different pages. I can navigate by (hamburger) menu or by calling the specific route (e.g. http://localhost/samplepage). Now I want to return plain JSON content when entering a specific route (e.g. http://localhost/myjson).
How can I manipulate the response so that it throws away all the Angular generated component code and instead return my plain JSON?
This seems to work:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular';
ngOnInit() {
const obj = {
name: 'Torsten',
age: 54
}
const thefile = new Blob([JSON.stringify(obj)], { type: "application/json" }) ;
let url = window.URL.createObjectURL(thefile);
window.location.href = url;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With