Switching from AngularJS to vanilla JavaScript or integrating AngularJS and Flask on a single server

It is common knowledge that angular has the ability to create a project and convert it into pure HTML, CSS, and js code. Similarly, I am looking to do the same for my AngularJS application. When I execute the app using npm start it works perfectly fine. My goal is to incorporate this app into my backend as an index.html template, eliminating the need for a separate front end server.

As depicted below, the backend represents a flask app while the frontend signifies an angular JS app.

I would appreciate any suggestions or solutions on:

  1. How can I convert the code into pure HTML, CSS, and JavaScript?
  2. How can I integrate the angular JS frontend directly into the flask backend as a template?
.
├── backend
│   ├── app.py
│   └── src
│       ├── db.py
│       ├── __init__.py
│       ├── run.py
│       └── secure.py
├── frontend
│   ├── app
│   │   ├── app.config.js
│   │   ├── app.css
│   │   ├── app.module.js
│   │   ├── home
|   |   |    ├── home.component.js
|   |   |    ├── home.component.spec.js
|   |   |    ├── home.module.js
|   |   |    └── home.template.html
│   │   ├── index.html
|   ├── package.json
│   ├── package-lock.json
│   └── README.md

Answer №1

After a whole day of trying, I stumbled upon a solution by accident while using the VS Code live server extension.

So, what should you do next?

index.html serves as the starting point. Therefore, copy and paste it into the templates folder (I am placing it inside the app folder within templates).

The next step involves copying all other files and folders such as components, app.config.js, app.css, app.module.js, etc. to the `static` folder.

Now, update paths in index.html within the templates folder following Flask rules using url_for.

Make changes to code samples:

<script src="{{url_for('static', filename='lib/angular/angular.js')}}"></script>
<script src="{{url_for('static', filename='lib/angular-route/angular-route.js')}}"></script>
<script src="{{url_for('static', filename='app.module.js')}}"></script>
<script src="{{url_for('static', filename='app.config.js')}}"></script>

<script src="{{url_for('static', filename='home/home.module.js')}}"></script>
<script src="{{url_for('static', filename='home/home.component.js')}}"></script>

Also, make small adjustments to components located in the static folder.

templateUrl: '/static/home/home.template.html'

Final directory structure

.
└── backend
    ├── app.py
    ├── src
    │   ├── db.py
    │   ├── __init__.py
    │   ├── run.py
    │   └── secure.py
    ├── static
    │   ├── app.config.js
    │   ├── app.css
    │   ├── app.module.js
    │   ├── home
    │   │   ├── home.component.js
    │   │   ├── home.component.spec.js
    │   │   ├── home.module.js
    │   │   └── home.template.html
    │   ├── img
    │   └── lib
    └── templates
        └── app
            ├── index-async.html
            └── index.html

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Chrome extensions: encountering 'variable undefined' error in the extension despite it being defined in the console

Within my chrome extension's content scripts, I have implemented a dynamic loading mechanism for an external JavaScript file onto an HTML page once it has finished loading. This JavaScript file is responsible for defining a variable called rfk. I have ...

What are the most effective techniques for utilizing JavaScript modules in both the Server and Browser environments?

Currently, I am in the process of developing a JavaScript project that utilizes NodeJS. There are certain objects that need to be shared between the client and server side. I attempted to employ the module system in Node, but struggled to find an appropria ...

What crucial element am I overlooking in the React Transition Group Component while implementing it for a carousel design?

I'm trying to add a feature to my Carousel where the opacity changes between images. When clicking on the icons, the images should transition smoothly. I've been using React Transition Group, but for some reason, it's not working as expected ...

Adding extra fields to an existing JSON response in a TypeScript REST API

I am in need of an additional column to be added to my response data. Currently, I am fetching data from multiple REST endpoints one by one and merging the results into a single JSON format to display them in an Angular Mat table. The columns that I want t ...

Sharing a Directive across multiple AngularJS modules: Tips and Tricks

AngularJS has truly captured my interest with its powerful capabilities. I am delving deeper into the world of Angular and finding myself falling in love with it more each day. Despite my efforts, certain doubts continue to linger, leaving me eager for cla ...

Setting up route handlers in Node.js on a pre-initialized HTTP server

Is there a way to add route handlers to an http server that is already instantiated? Most routers, including express, typically need to be passed into the http.createServer() method. For instance, with express: var server = http.createServer(app); My r ...

What is the process for inserting a scroll bar within a div element?

   I have recently created a webpage using some divs, along with a bit of CSS and JavaScript. I am struggling to figure out how to add a scrollbar to one of my divs. The code is not overly complex, as it includes both CSS and JavaScript. <html> & ...

Navigating the intricacies of passing a complex C# object through FromQuery

I have a client-side code snippet showcasing an object setup as follows: { "selectedItems": [ 4016, 3937 ], "selectedStatuses": [], "search": "foo" } My intention is to match this structure with a C# DTO: public class FilterModel { p ...

Issues with Fetch API and CORS in Web Browsers

Hello, I'm encountering an issue related to CORS and the Fetch API when using browsers. Currently, my setup involves running a NodeJS server built with Express on localhost:5000. This server responds to a GET request made to the URL /get_a, serving ...

React animation failing to render underline animation

After tinkering with the underline animation while scrolling down on Codepen using Javascript, I successfully implemented it. You can check out the working version on Codepen. This animation utilizes Intersection Observer and a generated svg for the underl ...

Tips for concealing links in ui-grid post-click with AngularJS

When using Angular-UI-Grid, I am working with the following paginated data: Name | Link A | Show Hide B | Show Hide Within my options: cellTemplate:'<div>' + ' <a ng-click="grid.appScope.show(row)">Show</a> ...

using java to invoke a server-side function within a mapReduce operation in mongodb

i have saved two functions in the "system.js" collection under the names "mapfun" and "reducefun" and now i am attempting to invoke these functions from Java. I am trying to utilize MapReduceCommand for this purpose but encountering difficulties in calling ...

Quasar Vue - Qselect component not populating with async data, showing [object Object] as default value

Within my created() method, I am making a call to Firestore to populate an array called ebscoCachedSearchesController in the data section. This array consists of objects that are correctly configured to be displayed in the qselect component. However, when ...

Learning React: Error - Unable to access the 'data' property when it is null

Currently, I am learning React by following a tutorial available at this link: http://facebook.github.io/react/docs/tutorial.html Specifically, I am focusing on the section related to fetching data from the server, which can be found here: http://facebook ...

Why is the Angular directive '=&' value binding to the scope showing as undefined?

An Angular directive has been defined within my application: (function() { 'use strict'; angular .module('almonds') .directive('security', ['$animate', 'AuthFactory', directive]); fun ...

Setting the Height of a Fixed Element to Extend to the Bottom of the Browser Window

I currently have a webpage layout featuring a header at the top, a fixed sidebar on the left side, and main content displayed on the right. A demo version of this layout can be viewed at http://jsbin.com/iqibew/3. The challenge I'm facing is ensuring ...

Trouble with serving CSS files using Express static directory

In my app.js file, I have the following code: app.use(express.static(path.join(__dirname, '../public'))); This code snippet is from my main layout page: <link rel="stylesheet" href="/css/styles.css"> Despite trying various combinations, ...

What is the best method for converting a variable with HTML content into a printable string?

In an attempt to display user-entered data from a text box to an HTML div, there seems to be an issue when the data contains HTML content. Instead of displaying the content as a string, it shows it as HTML elements. For example: let text = "<h1>Worl ...

Connecting node.js to a MySQL database on a WAMP/XAMPP server: A step-by-step guide

As a PHP programmer, I am experienced with WP, CI, and OC. However, I am a complete beginner when it comes to node.js and how to connect MySql with WAMP/XAMPP in a step-by-step method. If I were to set up a live server for this project, what would be the ...

Error message occurs when creating a pie chart with invalid values for the <path> element in Plottable/D3.js

For those who need the code snippets, you can find them for download here: index.html <!doctype html> <html> <head> <meta charset="UTF-8"> <!-- CSS placement for legend and fold change --> </head> <body ...