Reputation: 36001
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.
Upvotes: 21
Views: 6603
Reputation: 2899
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
Upvotes: 6
Reputation: 15240
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.
Upvotes: 6