4

I'm new to AngluarJs, and when I was trying it out (using Webstorm) I noticed that the url it takes me to is localhost:62345.

Why does a JavaScript library require a server? What is the purpose of the webserver?

Nico
  • 12,493
  • 5
  • 42
  • 62
Benyamin Noori
  • 860
  • 1
  • 8
  • 24
  • 1
    browsers won't run ajax requests from file protocol. Most SPA involve ajax usage. Angular itself does not run on server, it runs in browser. Open a static html file with no javascript in it from webstorm, will open on localhost server – charlietfl Jul 13 '15 at 12:40
  • Related: [Why does Angular require a server in their tutorials?](http://stackoverflow.com/q/31624686/435605). – AlikElzin-kilaka Feb 26 '17 at 06:05

2 Answers2

3

This is not angular but ide specific. Angular runs on frontend and hence there is no need to run a server to debug angular on front end as long as it doesn't involve server communication. Also you can try running from file explorer and have no issue.

binariedMe
  • 4,309
  • 1
  • 18
  • 34
  • 1
    OK, but what does the IDE need the server for? Why does it run my code on a specific port? – Benyamin Noori Jul 13 '15 at 12:37
  • 2
    not true if any templates are ajax loaded. Browsers block ajax on local file – charlietfl Jul 13 '15 at 12:37
  • fair enough @charlietfl... Although ajax call may be considered as server call only where server behaves as a static file server. – binariedMe Jul 13 '15 at 12:40
  • 1
    @BenyaminNoori It depends on IDE. Webstorm runs your project on a server so that you can make use of url pattern and may be more other reasons which I don't know. But for this has nothing to do with Angular. – binariedMe Jul 13 '15 at 12:41
  • It may be a case for webstorm, but in reality this has far more to do with SPA's than text editors – Ben Taliadoros Nov 07 '17 at 09:41
2

Angular Js doesn't require a server until you want to use angular directives like 'ng-include', or you want page routing or ajax request in your application.

This basic snippet in angular needs no server.

(function() {
  'use strict';

  angular.module('myapp', [])
    .controller('AppController', AppCtrl)

  AppCtrl.$inject = ['$scope'];

  function AppCtrl($scope) {
    var vm = this;
    vm.companyName = "AlertEnterprise";
    vm.rows = ["Rajesh", "Prashant"];
  }
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="myapp" ng-controller="AppController as appVM">

  <p>{{appVM.companyName}}</p>
  <p ng-repeat="row in appVM.rows">
    <span>{{row}}</span>
  </p>
</body>
Prashant K
  • 869
  • 9
  • 9