我已经克隆了这个项目https://github.com/enten/angular-universal 一切正常,我可以在 chrome 上查看源页面但是当我尝试动态更改数据(例如标题)时,当我检查Chrome 中的页面源。为什么?有没有办法改变服务器端的内容?
有关更多信息,我有一个显示评论列表和用于添加评论的输入字段的应用程序。第一次加载页面时,我可以在“页面源”中看到评论列表。但是当我添加评论,并查看页面来源时,内容与初始值相同。下面是一个简单的例子
这是 post.component.html
<p>{{result}}</p>
<button (click)="changeMessage()">Clique moi</button>
Run Code Online (Sandbox Code Playgroud)
和 post.component.ts
import { Component, OnInit, PLATFORM_ID, Inject, NgZone } from '@angular/core';
import { TransferState, makeStateKey } from '@angular/platform-browser';
import { isPlatformServer } from '@angular/common';
const RESULT_KEY = makeStateKey<string>('result');
declare var window: any;
@Component({
selector: 'app-post',
templateUrl: './post.component.html',
styleUrls: ['./post.component.css']
})
export class PostComponent implements OnInit {
public result;
private isServer: boolean;
constructor(
private tstate: TransferState,
@Inject(PLATFORM_ID) platformId,
private _ngZone: NgZone
) {
this.isServer = isPlatformServer(platformId);
} …Run Code Online (Sandbox Code Playgroud)