Nelson
Nelson

Reputation: 3262

On Angular 4, are controllers executed on the browser or server?

I am building an Angular 4 app. For local development I am running the app using ng serve.

It seems that Angular is running completely in the browser. Is ng serve a development only tool? Is it possible to run Angular controllers on the server and not the browser?

Upvotes: 4

Views: 1973

Answers (2)

Kai
Kai

Reputation: 2599

Angular is a purely client-side framework. The ng serve command just starts a lightweight development server that runs in the local environment. Running Angular on a server in production would seem to defeat the purpose of using an AJAX-based single page application framework, as its benefits come specifically from the fact that it's run in the browser.

Upvotes: 4

istrupin
istrupin

Reputation: 1543

Angular is indeed a front end framework, and as such it runs in the browser. ng serve runs a webpack development server so that you can see what your application looks like without having to spin up a separate webserver and bundle your code. When you deploy, you'll have an existing webserver host your angular code, but the controllers will just be responsible for client side (browser) markup. For server side routing (controllers on the server), you wouldn't use angular but some sort of server side web framework. For example, you can use NodeJS on the server side with server side controllers (often times these will return JSON data that your angular app will work with).

Upvotes: 7

Related Questions