Wikipedia:Reference desk/Archives/Computing/2022 June 4
Computing desk | ||
---|---|---|
< June 3 | << May | June | Jul >> | June 5 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
June 4
[edit]How can Angular know the build mode of an ASP.NET MVC application?
[edit]At work I am developing a system that is based on ASP.NET MVC. Part of the system uses Angular on the front end. The ASP.NET MVC controller serves a view page that has an Angular app declaration, which causes the Angular component to load. The templates and code files for the Angular component are stored in the ASP.NET MVC application's wwwroot
directory.
The thing here is that Angular is in development mode by default, but it should call enableProdMode()
to go into production mode in release builds shipped to customers. This caused a problem that how can Angular know if the system was built in release mode. I solved this by having main.ts
in Angular call an ASP.NET MVC controller method via AJAX, and this controller method simply returns a static boolean value which is determined by #if DEBUG
... #else
... #endif
. This works, but I was wondering if there was an easier way to do this completely at compile time, so the Angular code would not have to make an AJAX request each time. Is there one? JIP | Talk 20:24, 4 June 2022 (UTC)