angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.82k stars 27.5k forks source link

Angularjs as nodejs framework #9794

Closed aleclofabbro closed 10 years ago

aleclofabbro commented 10 years ago

referring to my SO Question: the purpose is to develop server applications using angularjs as container for services/DI/events modelled & configured by an html.. As you can see from my test, it is possible to do that. the test runs on top of jsdom and it just works ;) but: jsdom seems to be too slow.. it recreates a too much detailed browser environment.. i'm sure that many browser features are not necessary in a server environment (for example: user interaction events and maybe more..) I was wondering if it would be possible to create a thinner/faster/dumber browser environment in nodejs to let angularjs run into.. maybe using xmldom integrating it with a mock for window and document globals and .. what else? what angularjs expects to find in the browser env to run smoothly?

btford commented 10 years ago

Duplicate of #2104. Closing.

aleclofabbro commented 10 years ago

@btford There's a big difference against that duplicate:

2104 aims to Make server return fully rendered html ... and more generally generate/control the browser app on the server.

the purpose of mine is to develop nodejs apps using angular as framework, getting ng's benefits for module system, services definitions, DI, component lifecycle(by means of ng scopes), And, to benefit from the ng's natural html composition and configuration for nodejs app itself. example: A service may manage, for example, an mongodb connection.. A directive in the main html could use the mongodb service, getting parameters from html.. a fragment of the main html could look like:

...
<div ng-if="opendb" ng-controller="MogoDbCtrl as mongoCtrl" url="url"></div>

so the app has now a mongodb connection alive at the $scope.url when $scope.opendb is true. or also:

...
<div ng-repeat="user in loggedUsers">
  <div ng-repeat="room in user.rooms">
     <div x:chatroom-manager="room" user="user"></div>
  </div>
</div>

client side agnostic.. i'm talking about an ng-node-app, not talking about an browser ng-app

btford commented 10 years ago

Ah, this isn't a duplicate, sorry for misreading.

This sounds like a use-case entirely outside the scope of AngularJS. You're more than welcome to do this, but it is not something that I think we would ever accept patches for.

@vojtajina has published several DI libraries based on Angular's that I suspect would be more appropriate for your use case:

aleclofabbro commented 10 years ago

thanks for replying, any idea where should i post the Q for: I was wondering if it would be possible to create a thinner/faster/dumber browser environment in nodejs to let angularjs run into.. maybe using xmldom integrating it with a mock for window and document globals and .. what else? what angularjs expects to find in a fake-browser env to run smoothly?

caitp commented 10 years ago

you could try to get jsdom to run angular, but I'm not sure it would really work.

btford commented 10 years ago

I'm not sure. Have you looked at PhantomJS?

AngularJS does not target headless browsers.

aleclofabbro commented 10 years ago

@caitp i did it! angular just works in nodejs+jsdom, so the whole thing is already proven ! check this basic sample just jsdom is too complete browser env, so the nodejs app gets a bit slow.. i just want to improve performances..

@btford PhantomJS is a browser, headless but still.. and runs in it's own context and not in nodejs(i'm pretty sure)