I have cloned this project https://github.com/enten/angular-universal Everything is ok, I can view source page on chrome but when I try to change dynamically a data (for example the title) nothing changed when I check the page source in Chrome. Why? Is there a way to do change the server side content?
For more informations, I have an application that display a list of comments and an input field for adding a comment. When the page is load for the first time, I can see the list of the comments in "page source". But when I add a comment, and check the page source, the content is the same as the initial value. A simple example right below
Here is post.component.html
<p>{{result}}</p>
<button (click)="changeMessage()">Clique moi</button>
And the 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);
}
ngOnInit() {
if (this.tstate.hasKey(RESULT_KEY)) {
// We are in the browser
this.result = this.tstate.get(RESULT_KEY, '' as string);
} else if (this.isServer) {
// We are on the server
this.tstate.set(RESULT_KEY, 'Im created on the server!' as string);
} else {
// No result received
this.result = 'Im created in the browser!';
}
}
changeMessage() {
this.result = "Message changed";
}
}
So when the page load first, I see "Im created on the server!" when I check "view page source" on browser. After that, I click on the button I see change in the browser but the content still the same as initial value when I check "view page source"
Sorry for my english :) Thanks