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.
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.
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.
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.
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.
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
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.
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