As we know angular can build a project and convert to pure HTML, CSS, and js code. Similarly, I want my AngularJS application. When I run that app using npm start It works. I want to put that app in my backend as index.html as template so that no need for a separate front end server.
As shown below backend is a flask app and frontend is angular JS app.
Please suggest me the solution
.
├── 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
When I tried the whole day and finally found a solution accidentally in vs code live server extension. it is running there.
So what to do.
index.html is the starting point. So copy and paste it in the templates folder. (i am pasting inside the app folder which is in templates.
Next step, copy all other files and folders like components, app.config.js,app.css,app.module.jsetc tostatic` folder.
Now change paths in index.html inside templates folder accordingly flask rules using url_for.
Changed 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>
And also small changes to component which are in static folder
templateUrl: '/static/home/home.template.html'
.
└── 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
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