Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Angular require a server in their tutorials?

Tags:

Looking at the quick start and step by step tutorials, Angular requires a server.

Why does Angular require a server?

I'd like to focus on UI and having a working server all the time slows me down - especially in a big project, where the server is not stable all the time and has tons of integrations which aren't configured locally.

Edit [2015/08/12]: It seems that the server is required. Trying to run the step by step guide, doesn't work when loading the html statically (without a server). Nothing is shown. The myapp tag just doesn't get bounded the controller.

like image 317
AlikElzin-kilaka Avatar asked Jul 25 '15 08:07

AlikElzin-kilaka


People also ask

Why does Angular need a server?

Angular Universal executes on the server, generating static application pages that later get bootstrapped on the client. This means that the application generally renders more quickly, giving users a chance to view the application layout before it becomes fully interactive.

Can we run Angular without server?

You don't need a server-side engine to dynamically compose application pages because Angular does that on the client-side. If the application uses the Angular router, you must configure the server to return the application's host page ( index.html ) when asked for a file that it does not have.

Which server is used to deploy Angular?

Once the build of Angular application is created it is deployed on the production environment on the NodeJS server which is the most popular choice but the same build can be deployed on other alternative servers as well eg Tomcat.

Is Angular server or client?

Angular applications are client-side applications that execute on the browser - which means they are rendered on the client, not on the server. Thanks to Angular Universal, you can add server-side rendering to your app.


2 Answers

For security purpose, browser does not allow direct request on file system. It gives you error while working with routing and ajax requests in angular. So, you have to use simple HTTP server or you can create it using nodejs.

Refer Using node.js as a simple web server

Install apache2 server in linux :

sudo apt-get install apache2

After that you just have to put your code in /var/www/yourDirectory. Now you can access your code via http://localhost/yourDirectory

like image 94
Darshan Patel Avatar answered Sep 19 '22 17:09

Darshan Patel


Angular doesn't require a server per se, it is a static JS library.

However, you may quickly run into problems as soon as you start performing AJAX requests (e.g. when writing directives using templateUrl, loading partials using ngInclude, etc.). AJAX requests to local files are not allowed by most browsers as a security measure (although this feature can sometimes be disabled, see this post).

Bottom line, Angular suggests using a static server as a best practice, because it ensures that all features in their tutorials will work as described. For the most basic development, I use http-server which is very quick to fire up.

like image 39
Igor Raush Avatar answered Sep 16 '22 17:09

Igor Raush