nightingale2k1
nightingale2k1

Reputation: 10335

Angular 7 : how to tell Angular compiler / builder not to include data from js?

I have a project where I build a static web just for diplaying items. I don't have backend system so I just use Angular to display list of items from js. I want user able to update their item from js without re-compiling the angular app.

here is my sample https://stackblitz.com/edit/mockdatatestangular?embed=1&file=src/app/app.component.html

in here I have mockupdata.ts where I store all data that need to be displayed. I want this to be editable / renewable (I mean I can just upload new mockupdata.ts to server without re compile the entire app).

Is it possible to do that ?

Upvotes: 0

Views: 26

Answers (1)

Will Alexander
Will Alexander

Reputation: 3571

When you compile your Angular code, you turn it into JS code in one or more JS files. Your Angular app can't "read" from a TypeScript file. It's not dynamic in that way. In the process you're describing, your data is hardcoded in the final bundle.

What you might try doing is uploading your data in a JSON file and reading it from there, as long as your server allows for it. If not, you'll need some basic server which can return your data as JSON.

Upvotes: 1

Related Questions