Why does Angular require a server in its tutorials?

Looking for a quick start and step-by-step tutorials, Angular requires a server.

Why does Angular require a server?

I would like to focus on the user interface and constantly work on a working server, especially in a large project where the server is unstable all the time and has many integrations that are not configured locally.

Edit [2015/08/12]: It seems the server is needed. Trying to start the walkthrough does not work when loading html statically (without server). I can not see anything. The myapp tag simply does not limit the controller.

+8
angular
source share
2 answers

For security reasons, the browser does not allow a direct request to the file system. This gives you an error when working with routing and ajax requests in angular. Thus, you need to use a simple HTTP server, or you can create it using nodejs .

Refer Using Node.js as a Simple Web Server

Install apache2 server on Linux:

 sudo apt-get install apache2 

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

+2
source share

Angular does not require a server as such; it is a static JS library.

However, you can quickly run into problems as soon as you start executing AJAX requests (for example, when writing directives using templateUrl , loading partitions using ngInclude , etc.). AJAX requests to local files are not allowed by most browsers as a security measure (although this function can sometimes be disabled, see this post ).

On the bottom line, Angular suggests using a static server as a best practice, as it ensures that all the functions in their tutorials will work as described. For the most basic development, I use http-server , which starts very quickly.

+1
source share

All Articles