How to use the angular2-universal-preview.renderToStringWithPreboot function in angular2-universal-preview

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 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)
    });