Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-node-compile

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-node-compile

Compile angular templates, on Server side!

  • 1.5.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ng-node-compile

Compile html templates the angular way, in node js! this is a pretty new package, so don't hesitate adding issues or pull requests!

new ngcompile().$interpolate("hello {{name}}")({ name: 'Jhon doe' });

Install

$ npm install ng-node-compile

How to Use?

The library exposes several angular services, which will let you compile angular templates inside node:

###ngcompile

this is the function to create a angular enviorment. just

var ngEnviorment = new ngcompile([modules],[angularPath]);

arguments:

  • modules: optional. array of modules to inject to angular enviorment. example: [{name: 'testModule', path: './test.js'}]

  • angularPath: optional. path to angular.js file, in case you want another angular version.

$interpolate:

var ngcompile = require('ng-node-compile');
var ngEnviorment = new ngcompile();
ngEnviorment.$interpolate("hello {{name}}")({ name: 'Jhon doe' });

this wil return a string "hello Jhon doe"

$compile:

var ngcompile = require('ng-node-compile');
var ngEnviorment = new ngcompile();
ngEnviorment.$compile("<div ng-repeat=\"n in [1,2,3,4,5]\">hello {{name}} {{n}}</div>")({ name: 'Jhon doe' });

this wil return the following HTML:

##example using express and extra angular moduls:

app.js:

var express = require('express'),
    ngcompile = require('ng-node-compile');

var ngEnviorment = new ngcompile([{ name: 'test', path: './test.js' }]);
var app = express();

app.get('/', function (req, res) {
    res.send(ngEnviorment.$compile("<div ng-repeat=\"n in [1,2,3,4,5]\" yellow=\"{{n==3}}\">hello {{name}} {{n}}</div>")({ name: 'Jhon doe' }));
});

var server = app.listen(3000);

test.js:

angular.module('test', [])
.directive('yellow', [function () {
    return {
        restrict: "A",
        replace: false,
        scope: false,
        link: function (scope, element, attr) {
            if (attr['yellow'].toString() === "true") element.css('color', 'yellow')
        }
    }
}])

and the restlt simply looks this way:

result

Keywords

FAQs

Package last updated on 15 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc