How to use angular2-universal-preview - 8 common examples

To help you get started, we’ve selected a few angular2-universal-preview examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbabaioff / ng2-universal-seed / server.js View on Github external
var express   = require('express');
var ng2engine = require('angular2-universal-preview').ng2engine;

// Angular 2
var App = require('./dist/server/app').App;

var app = express();

// Express View
app.engine('.ng2.html', ng2engine);
app.set('views', __dirname);
app.set('view engine', 'ng2.html');


// static files
app.use(express.static(__dirname));


app.use('/', function(req, res) {
    res.render('index', {App: App});
});

app.listen(3000, function() {
    console.log('Listen on http://localhost:3000');
});
github angular / universal / modules / gulp-prerender / index.js View on Github external
return through.obj(function transform(file, enc, cb) {
    if (file.isStream()) {
      return cb(new PluginError('angular2-gulp-prerender', 'Streaming is not supported'));
    }
    var str = file.contents.toString();

    var renderPromise = universal.renderToString;
    var args = [config.App, config.providers];
    if (config.preboot) {
      renderPromise = universal.renderToStringWithPreboot;
      args.push(config.preboot);
    }

    renderPromise.apply(null, args)
    .then(function(serializedApp) {
      var html = str.replace(
        // 
        universal.selectorRegExpFactory(universal.selectorResolver(config.App)),
        // {{ serializedCmp }}
        serializedApp
      );

      file.contents = new Buffer(html);
github angular / universal / modules / gulp-prerender / index.js View on Github external
return through.obj(function transform(file, enc, cb) {
    if (file.isStream()) {
      return cb(new PluginError('angular2-gulp-prerender', 'Streaming is not supported'));
    }
    var str = file.contents.toString();

    var renderPromise = universal.renderToString;
    var args = [config.App, config.providers];
    if (config.preboot) {
      renderPromise = universal.renderToStringWithPreboot;
      args.push(config.preboot);
    }

    renderPromise.apply(null, args)
    .then(function(serializedApp) {
      var html = str.replace(
        // 
        universal.selectorRegExpFactory(universal.selectorResolver(config.App)),
        // {{ serializedCmp }}
        serializedApp
      );

      file.contents = new Buffer(html);

      cb(null, file)
    });
github angular / universal / modules / gulp-prerender / index.js View on Github external
.then(function(serializedApp) {
      var html = str.replace(
        // 
        universal.selectorRegExpFactory(universal.selectorResolver(config.App)),
        // {{ serializedCmp }}
        serializedApp
      );

      file.contents = new Buffer(html);

      cb(null, file)
    });
  });
github dotnet / aspnetcore / src / Microsoft.AspNet.AngularServices / Content / Node / angular-rendering.js View on Github external
renderToString: function(callback, options) {
        try {
            var component = findAngularComponent(options);
            var serverBindings = [
                ngRouter.ROUTER_BINDINGS,
                ngUniversal.HTTP_PROVIDERS,
                ngCore.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
                ngCore.provide(ngRouter.APP_BASE_HREF, { useValue: '/' }),
                ngUniversal.SERVER_LOCATION_PROVIDERS
            ];

            return ngUniversalRender.renderToString(component, serverBindings).then(
                function(successValue) { callback(null, successValue); },
                function(errorValue) { callback(errorValue); }
            );
        } catch (synchronousException) {
            callback(synchronousException);
        }
    }
};
github dotnet / aspnetcore / src / Microsoft.AspNet.AngularServices / Content / Node / angular-rendering.js View on Github external
renderToString: function(callback, options) {
        try {
            var component = findAngularComponent(options);
            var serverBindings = [
                ngRouter.ROUTER_BINDINGS,
                ngUniversal.HTTP_PROVIDERS,
                ngCore.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
                ngCore.provide(ngRouter.APP_BASE_HREF, { useValue: '/' }),
                ngUniversal.SERVER_LOCATION_PROVIDERS
            ];

            return ngUniversalRender.renderToString(component, serverBindings).then(
                function(successValue) { callback(null, successValue); },
                function(errorValue) { callback(errorValue); }
            );
        } catch (synchronousException) {
            callback(synchronousException);
        }
    }
};
github dotnet / aspnetcore / src / Microsoft.AspNet.AngularServices / Content / Node / angular-rendering.js View on Github external
renderToString: function(callback, options) {
        try {
            var component = findAngularComponent(options);
            var serverBindings = [
                ngRouter.ROUTER_BINDINGS,
                ngUniversal.HTTP_PROVIDERS,
                ngCore.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
                ngCore.provide(ngRouter.APP_BASE_HREF, { useValue: '/' }),
                ngUniversal.SERVER_LOCATION_PROVIDERS
            ];

            return ngUniversalRender.renderToString(component, serverBindings).then(
                function(successValue) { callback(null, successValue); },
                function(errorValue) { callback(errorValue); }
            );
        } catch (synchronousException) {
            callback(synchronousException);
        }
    }
};
github dotnet / aspnetcore / src / Microsoft.AspNet.AngularServices / Content / Node / angular-rendering.js View on Github external
renderToString: function(callback, options) {
        try {
            var component = findAngularComponent(options);
            var serverBindings = [
                ngRouter.ROUTER_BINDINGS,
                ngUniversal.HTTP_PROVIDERS,
                ngCore.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
                ngCore.provide(ngRouter.APP_BASE_HREF, { useValue: '/' }),
                ngUniversal.SERVER_LOCATION_PROVIDERS
            ];

            return ngUniversalRender.renderToString(component, serverBindings).then(
                function(successValue) { callback(null, successValue); },
                function(errorValue) { callback(errorValue); }
            );
        } catch (synchronousException) {
            callback(synchronousException);
        }
    }
};