元标记未在视图源中更新 - angular

Meta tag is not updating in view source - angular

我正在尝试更新 angular 6 和 angular univarsal 中的元标记,但它仅在检查元素中发生变化,而不是在视图页面源中发生变化,它在主页上保持不变。

Homepage.ts . . .

import { SeoserviceService } from "./../../services/seoservice.service";
 constructor(private metaService: Meta, public router: Router, public _seoService: SeoserviceService) {

   }
  ngOnInit() {


      this._seoService.updateTitle('Home');
      //Updating Description tag dynamically with title
      this._seoService.updateDescription('Home Page Description');
    }

}

about.ts . . .

import { SeoserviceService } from "./../../services/seoservice.service";
constructor(private metaService: Meta, public _seoService: SeoserviceService) {

   }

  ngOnInit() {
 this._seoService.updateTitle('About');
      //Updating Description tag dynamically with title
      this._seoService.updateDescription('About Page Description');

}

SeoserviceService.ts

import { Injectable } from '@angular/core';
import { Meta, Title } from '@angular/platform-browser';
@Injectable()
export class SeoserviceService {

  constructor(private title: Title, private meta: Meta) { }


  updateTitle(title: string) {
    this.title.setTitle(title);
  }

  updateDescription(desc: string) {
    this.meta.updateTag({ name: 'description', content: desc })
  }

}

server.ts

// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';

import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';

import * as express from 'express';
import { join } from 'path';
import { readFileSync } from 'fs';

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

// Express server
const app = express();

const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');

// Our index.html we'll use as our template
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main.bundle');

const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');

app.engine('html', (_, options, callback) => {
  renderModuleFactory(AppServerModuleNgFactory, {
    // Our index.html
    document: template,
    url: options.req.url,
    // DI so that we can get lazy-loading to work differently (since we need it to just instantly render it)
    extraProviders: [
      provideModuleMap(LAZY_MODULE_MAP)
    ]
  }).then(html => {
    callback(null, html);
  });
});

app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));

// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));

// All regular routes use the Universal engine
app.get('*', (req, res) => {
  res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });
});

// Start up the Node server
app.listen(PORT, () => {
  console.log(`Node server listening on http://localhost:${PORT}`);
});

当我 运行ning server.js 使用 npm 运行 build:ssr && npm 运行 serve:ssr 命令时给我的警告,如下 ./node_modules/@angular/platform-server/fesm5/platform-server.js 中的警告 410:26-50 "在 '@angular/common/http' 中找不到导出 'ɵHttpInterceptingHandler' @./node_modules/@angular/platform-server/fesm5/platform-server.js @./server.ts

./node_modules/@angular/platform-server/fesm5/platform-server.js 中的警告 852:35-51 "在 '@angular/common' 中找不到导出 'ViewportScroller' @./node_modules/@angular/platform-server/fesm5/platform-server.js @./server.ts

./node_modules/@angular/platform-server/fesm5/platform-server.js 中的警告 852:63-84 "在 '@angular/common' 中找不到导出 'ɵNullViewportScroller' @./node_modules/@angular/platform-server/fesm5/platform-server.js @./server.ts

       import { isPlatformBrowser, isPlatformServer } from 
       '@angular/common';
       import { PLATFORM_ID, Inject } from '@angular/core';

       export class Component
       {
        constructor(@Inject(PLATFORM_ID) private platformId: Object)
         {
        this.PutJquery()
         }
        PutJquery()
        {
       if (isPlatformBrowser(this.platformId)) {
        var authData = $.cookie('data');
        }
        }
      }