角度材料+角度通用

我试图在服务器端使用Angular Universal在Nodejs + Expressjs上呈现Angular应用程序。 在通过ng build --prod --app 1构建应用程序之后ng build --prod --app 1并使用webpack编译并通过node server.js运行应用程序。 当我在浏览器中打开应用程序时出错Current document does not have a doctype. This may cause some Angular Material components not to behave as expected. Current document does not have a doctype. This may cause some Angular Material components not to behave as expected.

// Load zone.js for the server.
require('zone.js/dist/zone-node');
require('reflect-metadata');

import * as express from 'express';
import { enableProdMode, ValueProvider } from '@angular/core';
import { renderModuleFactory } from '@angular/platform-server';
import { join } from 'path';
import { readFileSync } from 'fs';
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist-
server/main.bundle');

const template = readFileSync('./src/index.html', { encoding: 'utf8' });

const app = express();

app.engine('html', (_, options, callback) => {
  const opts = {
    document: template,
    url: options.req.url,
    extraProviders: [
      <ValueProvider>{
        provide: 'REQUEST',
        useValue: options.req,
      },
      provideModuleMap(LAZY_MODULE_MAP)
    ]
 };

renderModuleFactory(AppServerModuleNgFactory, opts)
  .then(html => callback(null, html));
});

app.set('view engine', 'html');
app.set('views', 'src');

app.get('*.*', express.static(join(__dirname, 'dist-server')));

app.get('*', (req, res) => {
  res.render('index', {req});
});

app.listen(5000, () => {
  console.log('listening on http://localhost:5000!');
});

看起来像这个与@ angular / material相关的bug,将来会被修复,但是有没有解决方法?


目前Angular Universal 2不支持Angular Material 2。 https://github.com/angular/universal#in-progress

链接地址: http://www.djcxy.com/p/31365.html

上一篇: Angular Material + Angular Universal

下一篇: Google Analytics / Client Side Only Code