Skip to content
Kyle J. Roux edited this page Sep 17, 2016 · 1 revision

Node-Ng (use angular services, events, and etc.. via commandline)

use cases:

  • command line programs
  • automated tests
  • fun...

Basics

  • wrap an anonymous function inside of a call to require("node-ng") ie:

      require("node-ng")(function(){
         // use angular here :+1: 
         var app = angular.module('app',[]);
         app.constant("VERSION","0.0.1");
         app.factory('getVersion',getVersion);
         getVersion.$inject = ['VERSION'];
         function getVersion(VERSION){
             return function(){
                 return VERSION;
             };
         }           
      });  
    
  • if you want to use angular only inside of services (as you should) then

    • define your main application code inside of a call to app.run(YOUR_RUN_FUNC)

    • then at the end of your program (right before the close of your anonymous function) you need to call the global function ng_bootstrap

    • and pass it your app (to bootstrap your app so it runs the run code) ie:

         app.run('getVersion','$http',function(getVersion,$http){
               // use $http service here
               console.log(getVersion());
         });
         ng_bootstrap(app);